home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / chipper.com / CHIPPER.C
C/C++ Source or Header  |  1991-09-15  |  84KB  |  2,916 lines

  1. /* (S)Chip-48 Assembler V2.11 by Christian Egeberg 2/11-'90 .. 20/8-'91 */
  2.  
  3. #define CopyRight "(S)Chip-48 Assembler V2.11 by Christian Egeberg 20/8-\'91"
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9.  
  10. /* Modify macro below to force Ansi or Kernighan-Ritchie prototypes */
  11. #define ANSI ( defined( c_plusplus ) || defined( __cplusplus ) || __STDC__ )
  12. /* Modify macro below to change procedure storage class */
  13. #define PROC
  14.  
  15. #define False     ( char )0
  16. #define True      ( char )~0
  17. #define UnDefined 0L
  18. #define Defined   ~0L
  19.  
  20. #define StartAddress 0x200L
  21. #define StopAddress  0xfffL
  22. #define CheckMagic   0x1081L
  23. #define WordMask     0xffffL
  24. #define AddrMask     0xfffL
  25. #define ByteMask     0xffL
  26. #define NibbleMask   0xfL
  27.  
  28. #define SpaceLength     32768 
  29. #define LineLength      255
  30. #define ParamLength     127
  31. #define SymbolLength    32
  32. #define ListLength      32
  33. #define StackLength     32  
  34. #define MaxBaseLength   16
  35. #define BinHpHeadLength 13
  36. #define FailExitCode    1
  37. #define SuccessExitCode 0
  38.  
  39. #define NullChar      '\0'
  40. #define BellChar      '\7'
  41. #define SpaceChar     ' '
  42. #define SeparatorChar ','
  43. #define RemarkChar    ';'
  44. #define SymbolChar    '_'
  45. #define LabelChar     ':'
  46. #define EqualChar     '='
  47. #define TextChar      '\''
  48. #define AddressChar   '\77'
  49. #define HexChar       '#'
  50. #define BinChar       '$'
  51. #define OctChar       '@'
  52. #define AscChar       '\"'
  53. #define StartChar     '('
  54. #define StopChar      ')'
  55. #define PlusChar      '+'
  56. #define MinusChar     '-'
  57. #define NotChar       '~'
  58. #define PowerChar     '!'
  59. #define ShlChar       '<'
  60. #define ShrChar       '>'
  61. #define MulChar       '*'
  62. #define FracChar      '/'
  63. #define AndChar       '&'
  64. #define OrChar        '|'
  65. #define XorChar       '^'
  66. #define DivChar       '\\'
  67. #define ModChar       '%'
  68.  
  69. #define WrongToken    0
  70. #define EqualToken    1
  71. #define AddToken      2
  72. #define AlignToken    3
  73. #define AndToken      4
  74. #define CallToken     5
  75. #define ClsToken      6
  76. #define DaToken       7
  77. #define DbToken       8
  78. #define DefineToken   9
  79. #define DrwToken     10
  80. #define DsToken      11
  81. #define DwToken      12
  82. #define ElseToken    13
  83. #define EndToken     14
  84. #define EndifToken   15
  85. #define EquToken     16
  86. #define ExitToken    17
  87. #define HighToken    18
  88. #define IfdefToken   19
  89. #define IfundToken   20
  90. #define IncludeToken 21
  91. #define JpToken      22
  92. #define LdToken      23
  93. #define LowToken     24
  94. #define OptionToken  25
  95. #define OrToken      26
  96. #define OrgToken     27
  97. #define RetToken     28
  98. #define RndToken     29
  99. #define ScdToken     30
  100. #define SclToken     31
  101. #define ScrToken     32
  102. #define SeToken      33
  103. #define ShlToken     34
  104. #define ShrToken     35
  105. #define SknpToken    36
  106. #define SkpToken     37
  107. #define SneToken     38
  108. #define SubToken     39
  109. #define SubnToken    40
  110. #define SysToken     41
  111. #define UndefToken   42
  112. #define UsedToken    43
  113. #define XorToken     44
  114. #define XrefToken    45
  115. #define LastToken    46
  116.  
  117. #define BadReg   0
  118. #define BReg     1
  119. #define DtReg    2
  120. #define FReg     3
  121. #define HfReg    4
  122. #define IReg     5
  123. #define KReg     6
  124. #define LfReg    7
  125. #define RReg     8
  126. #define StReg    9
  127. #define V0Reg   10
  128. #define V1Reg   11
  129. #define V2Reg   12
  130. #define V3Reg   13
  131. #define V4Reg   14
  132. #define V5Reg   15
  133. #define V6Reg   16
  134. #define V7Reg   17
  135. #define V8Reg   18
  136. #define V9Reg   19
  137. #define VaReg   20
  138. #define VbReg   21
  139. #define VcReg   22
  140. #define VdReg   23
  141. #define VeReg   24
  142. #define VfReg   25
  143. #define IiReg   26
  144. #define LastReg 27
  145.  
  146. #define AlignOnDefault  Defined
  147. #define Chip8Default    UnDefined
  148. #define Chip48Default   Defined
  149. #define Super10Default  UnDefined
  150. #define Super11Default  UnDefined
  151. #define UsedYesDefault  UnDefined
  152. #define UsedOnDefault   UnDefined
  153. #define XrefYesDefault  Defined
  154. #define XrefOnDefault   Defined
  155. #define HpHeadDefault   Defined
  156. #define HpAscDefault    UnDefined
  157.  
  158. typedef char CharSet[ 0x100 ];
  159. typedef char LineString[ LineLength + 1 ];
  160. typedef char ParamString[ ParamLength + 1 ];
  161. typedef char SymbolString[ SymbolLength + 1 ];
  162. typedef struct SpaceRecord {
  163.   unsigned int Size;
  164.   char *Start;
  165.   char *Point;
  166.   char *Index;
  167.   unsigned int Request;
  168. } SpaceRecord;
  169. typedef struct LocRecord *LocPointer;
  170. typedef struct LocRecord {
  171.   unsigned int Line; 
  172.   char *Name;
  173.   char *Text;
  174.   char Xref;
  175.   long int Addr;
  176. } LocRecord;
  177. typedef struct ReferRecord *ReferPointer;
  178. typedef struct ReferRecord {
  179.   LocRecord Loc;
  180.   ReferPointer Next;
  181. } ReferRecord;
  182. typedef struct ParamRecord *ParamPointer;
  183. typedef struct ParamRecord {
  184.   char *Param;
  185.   ParamPointer Next;
  186. } ParamRecord;
  187. typedef struct SymbolRecord *SymbolPointer;
  188. typedef struct SymbolRecord {
  189.   LocRecord Loc;
  190.   long int Value;
  191.   char *Symbol;
  192.   char *Expr;
  193.   ReferPointer Refer;
  194.   SymbolPointer Left;
  195.   SymbolPointer Right;
  196. } SymbolRecord;
  197. typedef struct InstRecord *InstPointer;
  198. typedef struct InstRecord { 
  199.   LocRecord Loc;
  200.   unsigned int Token;
  201.   unsigned int Count;
  202.   ParamPointer Params;
  203.   InstPointer Next;
  204. } InstRecord;
  205.  
  206. static char InExtDefault[] = ".chp";
  207. static char ListExtDefault[] = ".lst";
  208. static char DefFileName[] = ".";
  209. static char StdFileName[] = "-";
  210. static char StdInFileName[] = "stdin";
  211. static char StdOutFileName[] = "stdout";
  212. static char BinHpHeadText[] = "HPHP48-C";
  213. static char AscHpHeadText[] = "%%HP: T(3)A(R)F(.);\n";
  214.  
  215. static char RunErrorMessage[] = "Fatal error: ";
  216. static char RunWarningMessage[] = "Warning: ";
  217. static char WarningNumMessage[] = "Total number of warnings: ";
  218. static char EndOfFileMessage[] = "; End of file";
  219. static char NoTargetError[] = "Usage is.. chipper Target [Source] [List]";
  220. static char NoSourceError[] = "No source file found";
  221. static char FileAccessError[] = "Unable to open file";
  222. static char FileWriteError[] = "File or pipe output failed";
  223. static char AllocationError[] = "Unable to allocate more memory";
  224. static char SpaceAssertError[] = "Internal memory allocation mismatch";
  225. static char NestedIfdefError[] = "Too many nested conditions";
  226. static char BoundsError[] = "Outside legal address range";
  227. static char ParamCountWarning[] = "Incorrect number of parameters";
  228. static char DualSymbolWarning[] = "No directive recognized";
  229. static char NoOptionWarning[] = "Option not recognized";
  230. static char MissingSymbolWarning[] = "No symbol name specified";
  231. static char NoSymbolWarning[] = "Not a defined symbol";
  232. static char UnusedSymbolWarning[] = "Unused symbol detected";
  233. static char CopySymbolWarning[] = "Existing symbol redefined";
  234. static char UndefinedWarning[] = "Unable to evaluate parameter";
  235. static char RangeWarning[] = "Parameter out of range";
  236. static char NoRegisterWarning[] = "No register recognized";
  237. static char BadRegisterWarning[] = "Illegal register specified";
  238. static char NeedsChip8Warning[] = "Chip-8 spesific directive";
  239. static char NeedsChip48Warning[] = "Chip-48 spesific directive";
  240. static char NeedsSuper10Warning[] = "Super Chip-48 V1.0.. spesific directive";
  241. static char NeedsSuper11Warning[] = "Super Chip-48 V1.1.. spesific directive";
  242. static char MissingIfdefWarning[] = "No previous condition found";
  243. static char CountDefineWarning[] = "Unbalanced condition matching in file";
  244. static char InternalWarning[] = "Internal data structure mismatch";
  245.  
  246. static char AlignOnName[] = "ALIGNON";
  247. static char Chip8Name[] = "CHIP8";
  248. static char Chip48Name[] = "CHIP48";
  249. static char Super10Name[] = "SCHIP10";
  250. static char Super11Name[] = "SCHIP11";
  251. static char UsedYesName[] = "USEDYES";
  252. static char UsedOnName[] = "USEDON";
  253. static char XrefYesName[] = "XREFYES";
  254. static char XrefOnName[] = "XREFON";
  255. static char HpHeadName[] = "HPHEAD";
  256. static char HpAscName[] = "HPASC";
  257. static char HpBinName[] = "HPBIN";
  258. static char BinaryName[] = "BINARY";
  259. static char StringName[] = "STRING";
  260.  
  261. static char OptionYesName[] = "YES";
  262. static char OptionNoName[] = "NO";
  263. static char OptionOnName[] = "ON";
  264. static char OptionOffName[] = "OFF";
  265.  
  266. static SymbolString TokenText[ LastToken ] = 
  267.   { ",,,,,",   "=",       "ADD",     "ALIGN",   "AND",
  268.     "CALL",    "CLS",     "DA",      "DB",      "DEFINE",
  269.     "DRW",     "DS",      "DW",      "ELSE",    "END",     
  270.     "ENDIF",   "EQU",     "EXIT",    "HIGH",    "IFDEF",   
  271.     "IFUND",   "INCLUDE", "JP",      "LD",      "LOW",     
  272.     "OPTION",  "OR",      "ORG",     "RET",     "RND",     
  273.     "SCD",     "SCL",     "SCR",     "SE",      "SHL",     
  274.     "SHR",     "SKNP",    "SKP",     "SNE",     "SUB",     
  275.     "SUBN",    "SYS",     "UNDEF",   "USED",    "XOR",     
  276.     "XREF"                                                };
  277.  
  278. static SymbolString RegisterText[ LastReg ] =
  279.   { ",,,", "B",   "DT",  "F",   "HF",  "I",   "K",   "LF",
  280.     "R",   "ST",  "V0",  "V1",  "V2",  "V3",  "V4",  "V5",
  281.     "V6",  "V7",  "V8",  "V9",  "VA",  "VB",  "VC",  "VD",
  282.     "VE",  "VF",  "[I]"                                    };
  283.  
  284. static SpaceRecord Space = { SpaceLength, NULL, NULL, NULL, 0 };
  285.  
  286. static char StackStart[ StackLength + 1 ];
  287. static char *StackPoint = StackStart;
  288.  
  289. static CharSet Operators;
  290. static char StartOperator[] = { StartChar, NullChar };
  291. static char StopOperator[] = { StopChar, NullChar };
  292. static char UnaryOperator[] = { PlusChar, MinusChar, NotChar, NullChar };
  293. static char PowerOperator[] = { PowerChar, ShlChar, ShrChar, NullChar };
  294. static char MulDivOperator[] = { MulChar, FracChar, NullChar };
  295. static char PlusMinusOperator[] = { PlusChar, MinusChar, NullChar };
  296. static char BitWiseOperator[] = { AndChar, OrChar, XorChar, NullChar };
  297. static char DivModOperator[] = { DivChar, ModChar, NullChar };
  298. static ParamString DigitText = "0123456789ABCDEF.";
  299. static char NullString[] = "\0";
  300. static LineString Separator = "";
  301.  
  302. static long int DefinedValue = Defined;
  303. static long int DummyValue = UnDefined;
  304. static long int *AlignOnCond = &DummyValue;
  305. static long int *Chip8Cond = &DummyValue;
  306. static long int *Chip48Cond = &DummyValue;
  307. static long int *Super10Cond = &DummyValue;
  308. static long int *Super11Cond = &DummyValue;
  309. static long int *UsedYesCond = &DummyValue;
  310. static long int *UsedOnCond = &DummyValue;
  311. static long int *XrefYesCond = &DummyValue;
  312. static long int *XrefOnCond = &DummyValue;
  313. static long int *HpHeadCond = &DummyValue;
  314. static long int *HpAscCond = &DummyValue;
  315.  
  316. static InstPointer Instructions = NULL;
  317. static SymbolPointer Directives = NULL;
  318. static SymbolPointer Registers = NULL;
  319. static SymbolPointer Symbols= NULL;
  320. static SymbolPointer Conditions= NULL;
  321. static InstPointer InstPoint = NULL;
  322. static SymbolPointer SymbPoint = NULL;
  323. static SymbolPointer CurrentSymbol = NULL;
  324.  
  325. static long int FinalAddress = StartAddress;
  326. static LocRecord NullLocation = { 0, NullString, NullString, False, 0L };
  327. static LocRecord UsedLocation = { 0, NullString, NullString, True, 0L };
  328. static LocRecord Location = { 0, NullString, NullString, False, StartAddress };
  329. static unsigned int WarningCount = 0;
  330.  
  331. static FILE *InFile = NULL;
  332. static FILE *OutFile = NULL;
  333. static FILE *ListFile = NULL;
  334. static LineString InFileName = "";
  335. static LineString OutFileName = "";
  336. static LineString ListFileName = "";
  337.  
  338. static unsigned char Memory[ StopAddress - StartAddress + 1 ];
  339.  
  340. #if ANSI
  341.   static PROC char ResolveDivMod( char *Symbol, char **Param,
  342.     long int *Value, SymbolPointer Head, LocPointer Loc );
  343.   static PROC void DecodeFile( char *FileName, InstPointer *Head,
  344.     SymbolPointer Dir, SymbolPointer *Symb, SymbolPointer *Cond );
  345. #else
  346.   static PROC char ResolveDivMod();
  347.   static PROC void DecodeFile();
  348. #endif
  349.  
  350. #if ANSI
  351.   static PROC void RunError( char AbortFlag, char *Message )
  352. #else
  353.   static PROC void RunError( AbortFlag, Message )
  354.   char AbortFlag;
  355.   char *Message;
  356. #endif
  357. {
  358.   if( AbortFlag ) {
  359.     fprintf( stderr, "%c%s\n%s%s\n", BellChar, Separator, RunErrorMessage,
  360.       Message );
  361.     if( ListFile )
  362.       fprintf( ListFile, "%s\n%s%s\n", Separator, RunErrorMessage, Message );
  363.   } else {
  364.     fprintf( stderr, "%s\n%s%s\n", Separator, RunWarningMessage, Message );
  365.     if( ListFile )
  366.       fprintf( ListFile, "%s\n%s%s\n", Separator, RunWarningMessage, Message );
  367.   }
  368.   if( Location.Line ) {
  369.     fprintf( stderr, "Current file %s line %u\n%s\n", Location.Name,
  370.       Location.Line, Location.Text );
  371.     if( ListFile ) 
  372.       fprintf( ListFile, "Current file %s line %u\n%s\n", Location.Name,
  373.         Location.Line, Location.Text );
  374.   }
  375.   if( InstPoint ) {
  376.     fprintf( stderr, "Associated file %s line %u\n%s\n",
  377.       InstPoint->Loc.Name, InstPoint->Loc.Line, InstPoint->Loc.Text );
  378.     if( ListFile ) 
  379.       fprintf( ListFile, "Associated file %s line %u\n%s\n",
  380.         InstPoint->Loc.Name, InstPoint->Loc.Line, InstPoint->Loc.Text );
  381.   }
  382.   if( SymbPoint ) {
  383.     fprintf( stderr, "Symbol %s file %s line %u\n%s\n", SymbPoint->Symbol,
  384.       SymbPoint->Loc.Name, SymbPoint->Loc.Line, SymbPoint->Loc.Text );
  385.     if( ListFile ) 
  386.       fprintf( ListFile, "Symbol %s file %s line %u\n%s\n", SymbPoint->Symbol,
  387.         SymbPoint->Loc.Name, SymbPoint->Loc.Line, SymbPoint->Loc.Text );
  388.   }
  389.   fprintf( stderr, "%s\n", Separator );
  390.   if( ListFile )
  391.     fprintf( ListFile, "%s\n", Separator );
  392.   if( AbortFlag ) 
  393.     exit( FailExitCode );
  394.     /* exit function should close all files */
  395.   else
  396.     WarningCount++;
  397. }
  398.  
  399. #if ANSI
  400.   static PROC char *NumberString( char *Result, long int Value,
  401.     unsigned int Base, unsigned int Count )
  402. #else
  403.   static PROC char *NumberString( Result, Value, Base, Count )
  404.   char *Result;
  405.   long int Value;
  406.   unsigned int Base;
  407.   unsigned int Count;
  408. #endif
  409. {
  410.   char *Digit;
  411.  
  412.   Digit = Result + Count;
  413.   *( Digit-- ) = NullChar;
  414.   while(( Digit >= Result ) && ( Value > 0L )) {
  415.     *( Digit-- ) = DigitText[ Value % Base ];
  416.     Value /= Base;
  417.   }
  418.   while( Digit >= Result ) 
  419.     *( Digit-- ) = '0';
  420.   return( Result );
  421. }
  422.  
  423. #if ANSI
  424.   static PROC void ListInstruction( long int Address, unsigned int Count,
  425.     InstPointer Inst )
  426. #else
  427.   static PROC void ListInstruction( Address, Count, Inst )
  428.   long int Address;
  429.   unsigned int Count;
  430.   InstPointer Inst;
  431. #endif
  432. {
  433.   unsigned int This;
  434.   SymbolString HexText;
  435.  
  436.   if( fprintf( ListFile, "%s\n%s(%u).. %s: ", Inst->Loc.Text, Inst->Loc.Name,
  437.     Inst->Loc.Line, NumberString( HexText, Address, 16, 3 )) <= 0 )
  438.       RunError( True, FileWriteError );
  439.   for( This = 0; This < Count; This++ )
  440.     if( fprintf( ListFile, NumberString( HexText, ( long int )
  441.       Memory[ Address + This - StartAddress ], 16, 2 )) <= 0 )
  442.         RunError( True, FileWriteError );
  443.   fprintf( ListFile, "\n" );
  444. }
  445.  
  446. #if ANSI
  447.   static PROC void ListReference( ReferPointer Head )
  448. #else
  449.   static PROC void ListReference( Head )
  450.   ReferPointer Head;
  451. #endif
  452. {
  453.   for( ; Head; Head = Head->Next )
  454.     if( Head->Loc.Line && Head->Loc.Xref )
  455.       if( fprintf( ListFile, "  %s(%u)\n", Head->Loc.Name,
  456.         Head->Loc.Line ) <= 0 )
  457.           RunError( True, FileWriteError );
  458. }
  459.  
  460. #if ANSI
  461.   static PROC void ListSymbols( SymbolPointer Head )
  462. #else
  463.   static PROC void ListSymbols( Head )
  464.   SymbolPointer Head;
  465. #endif
  466. {
  467.   SymbolString HexText;
  468.  
  469.   if( Head ) {
  470.     if( Head->Left )
  471.       ListSymbols( Head->Left );
  472.     SymbPoint = Head;
  473.     if( !( *UsedYesCond ) && Head->Loc.Line && !( Head->Refer ))
  474.       RunError( False, UnusedSymbolWarning );
  475.     if( Head->Expr )
  476.       strcpy( HexText, "UND" );
  477.     else
  478.       NumberString( HexText, Head->Value, 16, 3 );
  479.     if( fprintf( ListFile, "%s %s %s(%u)\n", HexText, Head->Symbol,
  480.       Head->Loc.Name, Head->Loc.Line ) <= 0 )
  481.         RunError( True, FileWriteError );
  482.     if( *XrefYesCond )
  483.       ListReference( Head->Refer );
  484.     SymbPoint = NULL;
  485.     if( Head->Right )
  486.       ListSymbols( Head->Right );
  487.   }
  488. }
  489.  
  490. #if ANSI
  491.   static PROC void ListDefines( SymbolPointer Head )
  492. #else
  493.   static PROC void ListDefines( Head )
  494.   SymbolPointer Head;
  495. #endif
  496. {
  497.   if( Head ) {
  498.     if( Head->Left )
  499.       ListDefines( Head->Left );
  500.     if( Head->Value ) {
  501.       if( fprintf( ListFile, "DEF %s\n", Head->Symbol ) <= 0 )
  502.         RunError( True, FileWriteError );
  503.     } else 
  504.       if( fprintf( ListFile, "UND %s\n", Head->Symbol ) <= 0 )
  505.         RunError( True, FileWriteError );
  506.     if( Head->Right )
  507.       ListDefines( Head->Right );
  508.   }
  509. }
  510.  
  511. #if ANSI
  512.   static PROC void ListWarnings( void )
  513. #else
  514.   static PROC void ListWarnings()
  515. #endif
  516. {
  517.   if( fprintf( stderr, "%s%u\n", WarningNumMessage, WarningCount ) <= 0 )
  518.     RunError( True, FileWriteError );
  519.   if( fprintf( ListFile, "%s%u\n", WarningNumMessage, WarningCount ) <= 0 )
  520.     RunError( True, FileWriteError );
  521. }
  522.  
  523. #if ANSI
  524.   static PROC char *AssertSpace( SpaceRecord *Chain, unsigned int Size )
  525. #else
  526.   static PROC char *AssertSpace( Chain, Size )
  527.   SpaceRecord *Chain;
  528.   unsigned int Size;
  529. #endif
  530. {
  531.   if( Chain ) {
  532.     if( Chain->Request )
  533.       RunError( True, SpaceAssertError );
  534.     if( Size + sizeof( char * ) > Chain->Size )
  535.       RunError( True, SpaceAssertError );
  536.     if( !( Chain->Start )) {
  537.       Chain->Start = ( char * )malloc( Chain->Size );
  538.       if( !( Chain->Start ))
  539.         RunError( True, AllocationError );
  540.       Chain->Point = NULL;
  541.     }
  542.     if( !( Chain->Point )) {
  543.       Chain->Point = Chain->Start;
  544.       Chain->Index = NULL;
  545.     }
  546.     if( !( Chain->Index )) {
  547.       *( char ** )Chain->Point = NULL;
  548.       Chain->Index = Chain->Point + sizeof( char * );
  549.     }
  550.     if( Chain->Index + Size > Chain->Point + Chain->Size ) {
  551.       char *This;
  552.  
  553.       This = ( char * )malloc( Chain->Size );
  554.       if( !This )
  555.         RunError( True, AllocationError );
  556.       *( char ** )Chain->Point = This;
  557.       Chain->Point = This;
  558.       *( char ** )This = NULL;
  559.       Chain->Index = This + sizeof( char * );
  560.     }
  561.   } else
  562.     RunError( True, SpaceAssertError );
  563.   Chain->Request = Size;
  564.   return( Chain->Index );
  565. }
  566.  
  567. #if ANSI
  568.   static PROC void ClaimSpace( SpaceRecord *Chain, unsigned int Size )
  569. #else
  570.   static PROC void ClaimSpace( Chain, Size )
  571.   SpaceRecord *Chain;
  572.   unsigned int Size;
  573. #endif
  574. {
  575.   if( Chain ) {
  576.     if( !( Chain->Request ))
  577.       RunError( True, SpaceAssertError );
  578.     if( Size > Chain->Request )
  579.       RunError( True, SpaceAssertError );
  580.     Chain->Index += Size;
  581.     Chain->Request = 0;
  582.   } else
  583.     RunError( True, SpaceAssertError );
  584. }
  585.  
  586. #if ANSI
  587.   static PROC void ReleaseSpace( SpaceRecord *Chain )
  588. #else
  589.   static PROC void ReleaseSpace( Chain )
  590.   SpaceRecord *Chain;
  591. #endif
  592. {
  593.   char *This;
  594.   char *Next;
  595.  
  596.   if( Chain ) {
  597.     if( Chain->Request )
  598.       RunError( True, SpaceAssertError );
  599.     for( This = Chain->Start; This; ) {
  600.       Next = *( char ** )This;
  601.       free( This );
  602.       This = Next;
  603.     }
  604.     Chain->Start = NULL;
  605.     Chain->Point = NULL;
  606.     Chain->Index = NULL;
  607.     Chain->Request = 0;
  608.   } else
  609.     RunError( True, SpaceAssertError );
  610. }
  611.  
  612. #if ANSI
  613.   static PROC char OpenFiles( int argc, char *argv[] )
  614. #else
  615.   static PROC char OpenFiles( argc, argv )
  616.   int argc;
  617.   char *argv[]; 
  618. #endif
  619. {
  620.   if( argc >= 2 ) {
  621.     strcpy( OutFileName, argv[ 1 ]);
  622.     if( argc >= 3 )
  623.       strcpy( InFileName, argv[ 2 ]);
  624.     else {
  625.       strcpy( InFileName, OutFileName );
  626.       strcat( InFileName, InExtDefault );
  627.     }
  628.     if( !strcmp( InFileName, DefFileName )) {
  629.       strcpy( InFileName, OutFileName );
  630.       strcat( InFileName, InExtDefault );
  631.     }
  632.     if( !strcmp( InFileName, StdFileName )) 
  633.       strcpy( InFileName, StdInFileName );
  634.     if( argc >= 4 ) 
  635.       strcpy( ListFileName, argv[ 3 ]);
  636.     else {
  637.       strcpy( ListFileName, OutFileName );
  638.       strcat( ListFileName, ListExtDefault );
  639.     }
  640.     if( !strcmp( ListFileName, DefFileName )) {
  641.       strcpy( ListFileName, OutFileName );
  642.       strcat( ListFileName, ListExtDefault );
  643.     }
  644.     if( !strcmp( ListFileName, StdFileName )) 
  645.       strcpy( ListFileName, StdOutFileName );
  646.   } else
  647.     RunError( True, NoTargetError );
  648.   if( fprintf( stderr, "TargetFile: %s\n", OutFileName ) <= 0 )
  649.     RunError( True, FileWriteError );
  650.   OutFile = fopen( OutFileName, "w+b" );
  651.   if( !OutFile )
  652.     RunError( True, FileAccessError );
  653.   if( fprintf( stderr, "SourceFile: %s\n", InFileName ) <= 0 )
  654.     RunError( True, FileWriteError );
  655.   if( strcmp( InFileName, StdInFileName ))
  656.     InFile = fopen( InFileName, "r" );
  657.   else 
  658.     InFile = stdin;
  659.   if( !InFile )
  660.     RunError( True, NoSourceError );
  661.   if( fprintf( stderr, "ListFile: %s\n", ListFileName ) <= 0 )
  662.     RunError( True, FileWriteError );
  663.   if( strcmp( ListFileName, StdOutFileName )) 
  664.     ListFile = fopen( ListFileName, "w" );
  665.   else
  666.     ListFile = stdout;
  667.   if( !ListFile )
  668.     RunError( True, FileAccessError );
  669.   fprintf( stderr, "\n" );
  670.   if( fprintf( ListFile,
  671.     "%s\n\nTargetFile: %s\nSourceFile: %s\nListFile: %s\n\n", CopyRight,
  672.     OutFileName, InFileName, ListFileName ) <= 0 )
  673.       RunError( True, FileWriteError );
  674.   return( True );
  675. }
  676.  
  677. #if ANSI
  678.   static PROC void DefineReference( LocPointer Loc, ReferPointer *Head )
  679. #else
  680.   static PROC void DefineReference( Loc, Head )
  681.   LocPointer Loc;
  682.   ReferPointer *Head;
  683. #endif
  684. {
  685.   ReferPointer This;
  686.   ReferPointer Ref;
  687.   ReferPointer Last;
  688.   int Compare;
  689.  
  690.   if( Loc ) {
  691.     This = ( ReferPointer )AssertSpace( &Space, sizeof( ReferRecord ));
  692.     ClaimSpace( &Space, sizeof( ReferRecord ));
  693.     This->Loc = *Loc;
  694.     This->Next = NULL;
  695.     for( Last = NULL, Ref = *Head; Ref; ) {
  696.       Compare = strcmp( Loc->Name, Ref->Loc.Name );
  697.       if( !Compare ) {
  698.         if( Loc->Line < Ref->Loc.Line ) {
  699.           This->Next = Ref;
  700.           Ref = NULL;
  701.         } else {
  702.           Last = Ref;
  703.           Ref = Ref->Next;
  704.         }
  705.       } else 
  706.         if( Compare < 0 ) {
  707.           This->Next = Ref;
  708.           Ref = NULL;
  709.         } else {
  710.           Last = Ref;
  711.           Ref = Ref->Next;
  712.         }
  713.     }
  714.     if( !Last ) 
  715.       *Head = This;
  716.     else  
  717.       if(( Loc->Line != Last->Loc.Line ) || ( Loc->Name != Last->Loc.Name )) 
  718.         Last->Next = This;
  719.   }
  720. }
  721.  
  722. #if ANSI
  723.   static PROC char *StripSymbol( char *Result, char *Symbol )
  724. #else
  725.   static PROC char *StripSymbol( Result, Symbol )
  726.   char *Result;
  727.   char *Symbol;
  728. #endif
  729. {
  730.   if( *Symbol == SymbolChar ) 
  731.     Symbol++;
  732.   strncpy( Result, Symbol, SymbolLength );
  733.   Result[ SymbolLength ] = NullChar;
  734.   Symbol = Result + strlen( Result ) - 1;
  735.   if( *Symbol == LabelChar )
  736.     *Symbol = NullChar;
  737.   return( Result );
  738. }
  739.  
  740. #if ANSI
  741.   static PROC char DefineSymbol( char *RawSymbol, long int Value,
  742.     SymbolPointer *Head, LocPointer Loc )
  743. #else
  744.   static PROC char DefineSymbol( RawSymbol, Value, Head, Loc )
  745.   char *RawSymbol;
  746.   long int Value;
  747.   SymbolPointer *Head;
  748.   LocPointer Loc;
  749. #endif
  750. {
  751.   SymbolString Symbol;
  752.   SymbolPointer Symb;
  753.   SymbolPointer Last;
  754.   int Compare;
  755.  
  756.   StripSymbol( Symbol, RawSymbol );
  757.   Compare = 0;
  758.   Last = NULL;
  759.   Symb = *Head;
  760.   while( Symb ) {
  761.     Compare = strcmp( Symbol, Symb->Symbol );
  762.     if( !Compare ) {
  763.       Symb->Value = Value;
  764.       Symb->Expr = NULL;
  765.       if( Loc ) 
  766.         Symb->Loc = *Loc;
  767.       else
  768.         Symb->Loc = NullLocation; 
  769.       if( Symb->Loc.Xref )
  770.         DefineReference( &( Symb->Loc ), &( Symb->Refer ));
  771.       CurrentSymbol = Symb;
  772.       return( False );
  773.     }
  774.     Last = Symb;
  775.     if( Compare <= 0 )
  776.       Symb = Symb->Left;
  777.     else
  778.       Symb = Symb->Right;
  779.   }
  780.   Symb = ( SymbolPointer )AssertSpace( &Space, sizeof( SymbolRecord ));
  781.   ClaimSpace( &Space, sizeof( SymbolRecord ));
  782.   Symb->Symbol = ( char * )AssertSpace( &Space, sizeof( SymbolString ));
  783.   strcpy( Symb->Symbol, Symbol );
  784.   ClaimSpace( &Space, ( unsigned int )( strlen( Symb->Symbol ) + 1 ));
  785.   Symb->Value = Value;
  786.   Symb->Expr = NULL;
  787.   if( Loc )
  788.     Symb->Loc = *Loc;
  789.   else
  790.     Symb->Loc = NullLocation; 
  791.   Symb->Refer = NULL;
  792.   if( *UsedOnCond )
  793.     DefineReference( &NullLocation, &( Symb->Refer ));
  794.   Symb->Left = NULL;
  795.   Symb->Right = NULL;
  796.   if( !Last )
  797.     *Head = Symb;
  798.   else 
  799.     if( Compare <= 0 )
  800.       Last->Left = Symb;
  801.     else
  802.       Last->Right = Symb;
  803.   CurrentSymbol = Symb;
  804.   return( True );
  805. }
  806.  
  807. #if ANSI
  808.   static PROC char ResolveOption( char *Option, long int *YesNoPoint,
  809.     long int *OnOffPoint )
  810. #else
  811.   static PROC char ResolveOption( Option, YesNoPoint, OnOffPoint )
  812.   char *Option;
  813.   long int *YesNoPoint;
  814.   long int *OnOffPoint;
  815. #endif
  816. {
  817.   char Result;
  818.  
  819.   Result = True;
  820.   if( !strcmp( Option, OptionYesName )) {
  821.     *YesNoPoint = Defined;
  822.     Result = False;
  823.   }
  824.   if( !strcmp( Option, OptionNoName )) {
  825.     *YesNoPoint = UnDefined;
  826.     Result = False;
  827.   }
  828.   if( !strcmp( Option, OptionOnName )) {
  829.     *OnOffPoint = Defined;
  830.     Result = False;
  831.   }
  832.   if( !strcmp( Option, OptionOffName )) {
  833.     *OnOffPoint = UnDefined;
  834.     Result = False;
  835.   }
  836.   return( Result );
  837. }
  838.  
  839. #if ANSI
  840.   static PROC char ResolveSymbol( char *RawSymbol, long int *Value,
  841.     SymbolPointer Head, LocPointer Loc )
  842. #else
  843.   static PROC char ResolveSymbol( RawSymbol, Value, Head, Loc )
  844.   char *RawSymbol;
  845.   long int *Value;
  846.   SymbolPointer Head;
  847.   LocPointer Loc;
  848. #endif
  849. {
  850.   SymbolString Symbol;
  851.   int Compare;
  852.   char Result;
  853.  
  854.   Result = False;
  855.   *Value = 0L;
  856.   StripSymbol( Symbol, RawSymbol );
  857.   while( Head ) {
  858.     Compare = strcmp( Symbol, Head->Symbol );
  859.     if( !Compare ) {
  860.       *Value = Head->Value;
  861.       if( Loc )
  862.         if( Loc->Xref )
  863.           DefineReference( Loc, &( Head->Refer ));
  864.       if( !( Head->Expr ))
  865.         Result = True;
  866.       Head = NULL;
  867.     } else {
  868.       if( Compare <= 0 )
  869.         Head = Head->Left;
  870.       else
  871.         Head = Head->Right;
  872.     }
  873.   }
  874.   return( Result );
  875. }
  876.  
  877. #if ANSI
  878.   static PROC char ResolveNumber( char *Symbol, int Base, long int *Value )
  879. #else
  880.   static PROC char ResolveNumber( Symbol, Base, Value )
  881.   char *Symbol;
  882.   int Base;
  883.   long int *Value;
  884. #endif
  885. {
  886.   char *Digit;
  887.   char Result;
  888.   unsigned int Count;
  889.   unsigned int Length;
  890.  
  891.   Result = True;
  892.   if( !( *Symbol ))
  893.     Result = False;
  894.   *Value = 0L;
  895.   Length = strlen( Symbol );
  896.   for( Count = 1; Count <= Length; Count++ ) {
  897.     Digit = strchr( DigitText, Symbol[ Count - 1 ]);
  898.     if( !Digit ) {
  899.       Result = False;
  900.       Count = Length;
  901.     } else {
  902.       if(( Digit - DigitText ) >= MaxBaseLength ) 
  903.         Digit = DigitText;
  904.       if(( Digit - DigitText ) > Base ) {
  905.         Result = False;
  906.         Count = Length;
  907.       } else
  908.         *Value = Base * ( *Value ) + ( Digit - DigitText );
  909.     }
  910.   }
  911.   return( Result );
  912. }
  913.  
  914. #if ANSI
  915.   static PROC char ResolveValue( char *Symbol, long int *Value,
  916.     SymbolPointer Head, LocPointer Loc )
  917. #else
  918.   static PROC char ResolveValue( Symbol, Value, Head, Loc )
  919.   char *Symbol;
  920.   long int *Value;
  921.   SymbolPointer Head;
  922.   LocPointer Loc;
  923. #endif
  924. {
  925.   char Result;
  926.  
  927.   Result = False;
  928.   *Value = 0L;
  929.   if(( Symbol[ 0 ] == AddressChar ) && !( Symbol[ 1 ]) && Loc ) {
  930.     *Value = Loc->Addr;
  931.     return( True );
  932.   }
  933.   switch( Symbol[ 0 ]) {
  934.     case HexChar:
  935.       Result = ResolveNumber( Symbol + 1, 16, Value );
  936.       break;
  937.     case BinChar:
  938.       Result = ResolveNumber( Symbol + 1, 2, Value );
  939.       break;
  940.     case OctChar:
  941.       Result = ResolveNumber( Symbol + 1, 8, Value );
  942.       break;
  943.     case AscChar:
  944.       if( Symbol[ 1 ]) {
  945.         *Value = Symbol[ 1 ];
  946.         if( !( Symbol[ 2 ]))
  947.         Result = True;
  948.       }
  949.       break;
  950.     default:
  951.       if( isdigit( Symbol[ 0 ]))
  952.         Result = ResolveNumber( Symbol, 10, Value );
  953.       else
  954.         Result = ResolveSymbol( Symbol, Value, Head, Loc );
  955.       break;
  956.   }
  957.   return( Result );
  958. }
  959.  
  960. #if ANSI
  961.   static PROC char *SplitParam( char *Result, char **Param )
  962. #else
  963.   static PROC char *SplitParam( Result, Param )
  964.   char *Result;
  965.   char **Param;
  966. #endif
  967. {
  968.   char *Start;
  969.   char *Count;
  970.   char *Store;
  971.   char Reading;
  972.  
  973.   Store = Result;
  974.   *Store = NullChar;
  975.   Reading = True;
  976.   for( Start = NULL, Count = *Param; *Count; Count++ ) 
  977.     if( isgraph( *Count )) {
  978.       Start = Count;
  979.       Count = NullString;
  980.     }
  981.   if( Start ) {
  982.     Count = Start;
  983.     if( Operators[ *Count ]) {
  984.       *( Store++ ) = *Count;
  985.       *( Store++ ) = NullChar; 
  986.       *Param = Count + 1;
  987.       Reading = False;
  988.     } else 
  989.       for( ; *Count; Count++ ) 
  990.         if(( !isgraph( *Count )) || Operators[ *Count ]) {
  991.           *Param = Count;
  992.           Count = NullString;
  993.           Reading = False;
  994.         } else 
  995.           *( Store++ ) = *Count;
  996.   }
  997.   if( Reading )
  998.     *Param = NullString;
  999.   *( Store++ ) = NullChar;
  1000.   return( Result );
  1001. }
  1002.  
  1003. #if ANSI
  1004.   static PROC char ResolveOperator( char *Symbol, char *Token, char *Legal )
  1005. #else
  1006.   static PROC char ResolveOperator( Symbol, Token, Legal )
  1007.   char *Symbol;
  1008.   char *Token;
  1009.   char *Legal;
  1010. #endif
  1011. {
  1012.   *Token = *Symbol;
  1013.   if(( *Token ) && strchr( Legal, *Token ))
  1014.     return( True ); 
  1015.   else
  1016.     return( False ); 
  1017. }
  1018.  
  1019. #if ANSI
  1020.   static PROC char ResolveSingle( char Token, long int *Value )
  1021. #else
  1022.   static PROC char ResolveSingle( Token, Value )
  1023.   char Token;
  1024.   long int *Value;
  1025. #endif
  1026. {
  1027.   char Result;
  1028.  
  1029.   Result = True;
  1030.   switch( Token ) {
  1031.     case PlusChar:
  1032.       /* Nothing to be done */
  1033.       break;
  1034.     case MinusChar:
  1035.       *Value = -( *Value );
  1036.       break;
  1037.     case NotChar:
  1038.       *Value = ~( *Value );
  1039.       break;
  1040.     default:
  1041.       Result = False;
  1042.       break;
  1043.   }
  1044.   return( Result );
  1045. }
  1046.  
  1047. #if ANSI
  1048.   static PROC char ResolveDouble( char Token, long int *Value,
  1049.     long int Operand )
  1050. #else
  1051.   static PROC char ResolveDouble( Token, Value, Operand )
  1052.   char Token;
  1053.   long int *Value;
  1054.   long int Operand;
  1055. #endif
  1056. {
  1057.   long int Count;
  1058.   long int This;
  1059.   char Result;
  1060.  
  1061.   Result = True;
  1062.   switch( Token ) {
  1063.     case PowerChar:
  1064.       This = 1;
  1065.       for( Count = 1; Count <= Operand; Count++ )
  1066.         This *= *Value;
  1067.       *Value = This;
  1068.       break;
  1069.     case ShlChar:
  1070.       *Value <<= Operand;
  1071.       break;
  1072.     case ShrChar:
  1073.       *Value >>= Operand;
  1074.       break;
  1075.     case MulChar:
  1076.       *Value *= Operand;
  1077.       break;
  1078.     case FracChar:
  1079.     case DivChar:
  1080.       *Value /= Operand;
  1081.       break;
  1082.     case PlusChar:
  1083.       *Value += Operand;
  1084.       break;
  1085.     case MinusChar:
  1086.       *Value -= Operand;
  1087.       break;
  1088.     case AndChar:
  1089.       *Value &= Operand;
  1090.       break;
  1091.     case OrChar:
  1092.       *Value |= Operand;
  1093.       break;
  1094.     case XorChar:
  1095.       *Value ^= Operand;
  1096.       break;
  1097.     case ModChar:
  1098.       *Value %= Operand;
  1099.       break;
  1100.     default:
  1101.       Result = False;
  1102.       break;
  1103.   }
  1104.   return( Result );
  1105. }
  1106.  
  1107. #if ANSI
  1108.   static PROC char ResolveParent( char *Symbol, char **Param, long int *Value,
  1109.     SymbolPointer Head, LocPointer Loc )
  1110. #else
  1111.   static PROC char ResolveParent( Symbol, Param, Value, Head, Loc )
  1112.   char *Symbol;
  1113.   char **Param;
  1114.   long int *Value;
  1115.   SymbolPointer Head;
  1116.   LocPointer Loc;
  1117. #endif
  1118. {
  1119.   char Token;
  1120.   char Status;
  1121.  
  1122.   if( ResolveOperator( Symbol, &Token, StartOperator )) {
  1123.     SplitParam( Symbol, Param );
  1124.     Status = ResolveDivMod( Symbol, Param, Value, Head, Loc );
  1125.     if( !ResolveOperator( Symbol, &Token, StopOperator ))
  1126.       Status = False;
  1127.     SplitParam( Symbol, Param );
  1128.   } else {
  1129.     Status = ResolveValue( Symbol, Value, Head, Loc );
  1130.     SplitParam( Symbol, Param );
  1131.   }
  1132.   return( Status );
  1133. }
  1134.  
  1135. #if ANSI
  1136.   static PROC char ResolveUnary( char *Symbol, char **Param, long int *Value,
  1137.     SymbolPointer Head, LocPointer Loc )
  1138. #else
  1139.   static PROC char ResolveUnary( Symbol, Param, Value, Head, Loc )
  1140.   char *Symbol;
  1141.   char **Param;
  1142.   long int *Value;
  1143.   SymbolPointer Head;
  1144.   LocPointer Loc;
  1145. #endif
  1146. {
  1147.   char Token;
  1148.   char Status;
  1149.  
  1150.   if( ResolveOperator( Symbol, &Token, UnaryOperator )) {
  1151.     SplitParam( Symbol, Param );
  1152.     Status = ResolveParent( Symbol, Param, Value, Head, Loc );
  1153.     Status = Status & ResolveSingle( Token, Value );
  1154.   } else
  1155.     Status = ResolveParent( Symbol, Param, Value, Head, Loc );
  1156.   return( Status );
  1157. }
  1158.  
  1159. #if ANSI
  1160.   static PROC char ResolvePower( char *Symbol, char **Param, long int *Value,
  1161.     SymbolPointer Head, LocPointer Loc )
  1162. #else
  1163.   static PROC char ResolvePower( Symbol, Param, Value, Head, Loc )
  1164.   char *Symbol;
  1165.   char **Param;
  1166.   long int *Value;
  1167.   SymbolPointer Head;
  1168.   LocPointer Loc;
  1169. #endif
  1170. {
  1171.   long int Operand;
  1172.   char Token;
  1173.   char Status;
  1174.  
  1175.   Operand = 0L;
  1176.   Status = ResolveUnary( Symbol, Param, Value, Head, Loc );
  1177.   while( ResolveOperator( Symbol, &Token, PowerOperator )) {
  1178.     SplitParam( Symbol, Param );
  1179.     Status = Status & ResolveUnary( Symbol, Param, &Operand, Head, Loc );
  1180.     Status = Status & ResolveDouble( Token, Value, Operand );
  1181.   }
  1182.   return( Status );
  1183. }
  1184.  
  1185. #if ANSI
  1186.   static PROC char ResolveMulDiv( char *Symbol, char **Param, long int *Value,
  1187.     SymbolPointer Head, LocPointer Loc )
  1188. #else
  1189.   static PROC char ResolveMulDiv( Symbol, Param, Value, Head, Loc )
  1190.   char *Symbol;
  1191.   char **Param;
  1192.   long int *Value;
  1193.   SymbolPointer Head;
  1194.   LocPointer Loc;
  1195. #endif
  1196. {
  1197.   long int Operand;
  1198.   char Token;
  1199.   char Status;
  1200.  
  1201.   Operand = 0L;
  1202.   Status = ResolvePower( Symbol, Param, Value, Head, Loc );
  1203.   while( ResolveOperator( Symbol, &Token, MulDivOperator )) {
  1204.     SplitParam( Symbol, Param );
  1205.     Status = Status & ResolvePower( Symbol, Param, &Operand, Head, Loc );
  1206.     Status = Status & ResolveDouble( Token, Value, Operand );
  1207.   }
  1208.   return( Status );
  1209. }
  1210.  
  1211. #if ANSI
  1212.   static PROC char ResolvePlusMinus( char *Symbol, char **Param,
  1213.     long int *Value, SymbolPointer Head, LocPointer Loc )
  1214. #else
  1215.   static PROC char ResolvePlusMinus( Symbol, Param, Value, Head, Loc )
  1216.   char *Symbol;
  1217.   char **Param;
  1218.   long int *Value;
  1219.   SymbolPointer Head;
  1220.   LocPointer Loc;
  1221. #endif
  1222. {
  1223.   long int Operand;
  1224.   char Token;
  1225.   char Status;
  1226.  
  1227.   Operand = 0L;
  1228.   Status = ResolveMulDiv( Symbol, Param, Value, Head, Loc );
  1229.   while( ResolveOperator( Symbol, &Token, PlusMinusOperator )) {
  1230.     SplitParam( Symbol, Param );
  1231.     Status = Status & ResolveMulDiv( Symbol, Param, &Operand, Head, Loc );
  1232.     Status = Status & ResolveDouble( Token, Value, Operand );
  1233.   }
  1234.   return( Status );
  1235. }
  1236.  
  1237. #if ANSI
  1238.   static PROC char ResolveBitWise( char *Symbol, char **Param, long int *Value,
  1239.     SymbolPointer Head, LocPointer Loc )
  1240. #else
  1241.   static PROC char ResolveBitWise( Symbol, Param, Value, Head, Loc )
  1242.   char *Symbol;
  1243.   char **Param;
  1244.   long int *Value;
  1245.   SymbolPointer Head;
  1246.   LocPointer Loc;
  1247. #endif
  1248. {
  1249.   long int Operand;
  1250.   char Token;
  1251.   char Status;
  1252.  
  1253.   Operand = 0L;
  1254.   Status = ResolvePlusMinus( Symbol, Param, Value, Head, Loc );
  1255.   while( ResolveOperator( Symbol, &Token, BitWiseOperator )) {
  1256.     SplitParam( Symbol, Param );
  1257.     Status = Status & ResolvePlusMinus( Symbol, Param, &Operand, Head, Loc );
  1258.     Status = Status & ResolveDouble( Token, Value, Operand );
  1259.   }
  1260.   return( Status );
  1261. }
  1262.  
  1263. #if ANSI
  1264.   static PROC char ResolveDivMod( char *Symbol, char **Param, long int *Value,
  1265.     SymbolPointer Head, LocPointer Loc )
  1266. #else
  1267.   static PROC char ResolveDivMod( Symbol, Param, Value, Head, Loc )
  1268.   char *Symbol;
  1269.   char **Param;
  1270.   long int *Value;
  1271.   SymbolPointer Head;
  1272.   LocPointer Loc;
  1273. #endif
  1274. {
  1275.   long int Operand;
  1276.   char Token;
  1277.   char Status;
  1278.  
  1279.   Operand = 0L;
  1280.   Status = ResolveBitWise( Symbol, Param, Value, Head, Loc );
  1281.   while( ResolveOperator( Symbol, &Token, DivModOperator )) {
  1282.     SplitParam( Symbol, Param );
  1283.     Status = Status & ResolveBitWise( Symbol, Param, &Operand, Head, Loc );
  1284.     Status = Status & ResolveDouble( Token, Value, Operand );
  1285.   }
  1286.   return( Status );
  1287. }
  1288.  
  1289. #if ANSI
  1290.   static PROC char ResolveExpression( char **Param, long int *Value,
  1291.     SymbolPointer Head, LocPointer Loc )
  1292. #else
  1293.   static PROC char ResolveExpression( Param, Value, Head, Loc )
  1294.   char **Param;
  1295.   long int *Value;
  1296.   SymbolPointer Head;
  1297.   LocPointer Loc;
  1298. #endif
  1299. {
  1300.   SymbolString Symbol;
  1301.   char Result;
  1302.  
  1303.   Result = False;
  1304.   *Value = 0L;
  1305.   SplitParam( Symbol, Param );
  1306.   if( *Symbol )
  1307.     Result = ResolveDivMod( Symbol, Param, Value, Head, Loc );
  1308.   if( *Symbol )
  1309.     return( False );
  1310.   else
  1311.     return( Result );
  1312. }
  1313.  
  1314. #if ANSI
  1315.   static PROC void MissingEquations( SymbolPointer Head )
  1316. #else
  1317.   static PROC void MissingEquations( Head )
  1318.   SymbolPointer Head;
  1319. #endif
  1320. {
  1321.   if( Head ) {
  1322.     MissingEquations( Head->Left );
  1323.     if( Head->Expr ) {
  1324.       SymbPoint = Head;
  1325.       RunError( False, UndefinedWarning );
  1326.       SymbPoint = NULL;
  1327.     }
  1328.     MissingEquations( Head->Right ); 
  1329.   }
  1330. }
  1331.  
  1332. #if ANSI
  1333.   static PROC unsigned int ResolveTraversal( SymbolPointer Symb,
  1334.     SymbolPointer Head )
  1335. #else
  1336.   static PROC unsigned int ResolveTraversal( Symb, Head )
  1337.   SymbolPointer Symb;
  1338.   SymbolPointer Head;
  1339. #endif
  1340. {
  1341.   char *Expression;
  1342.   long int Value;
  1343.   unsigned int Count;
  1344.  
  1345.   Count = 0;
  1346.   if( Symb ) {
  1347.     if( Symb->Expr ) {
  1348.       Expression = Symb->Expr;
  1349.       if( ResolveExpression( &Expression, &Value, Head, &( Symb->Loc ))) {
  1350.         Symb->Value = Value;
  1351.         Symb->Expr = NULL; 
  1352.       } else
  1353.         Count++;
  1354.     }
  1355.     Count += ResolveTraversal( Symb->Left, Head );
  1356.     Count += ResolveTraversal( Symb->Right, Head ); 
  1357.   }
  1358.   return( Count );
  1359. }
  1360.  
  1361. #if ANSI
  1362.   static PROC void ResolveEquations( SymbolPointer Head )
  1363. #else
  1364.   static PROC void ResolveEquations( Head )
  1365.   SymbolPointer Head;
  1366. #endif
  1367. {
  1368.   unsigned int Count;
  1369.   unsigned int Remains;
  1370.  
  1371.   Count = 0;
  1372.   do {
  1373.     Remains = Count;
  1374.     Count = ResolveTraversal( Head, Head );
  1375.   } while( Count && ( Count != Remains ));
  1376.   if( Count ) 
  1377.     MissingEquations( Head );
  1378. }
  1379.  
  1380. #if ANSI
  1381.   static PROC void StoreSymbolList( SymbolString SymbolText[],
  1382.     unsigned int Min, unsigned int Max, SymbolPointer *DirHead )
  1383. #else
  1384.   static PROC void StoreSymbolList( SymbolText, Min, Max, DirHead )
  1385.   SymbolString SymbolText[];
  1386.   unsigned int Min;
  1387.   unsigned int Max;
  1388.   SymbolPointer *DirHead;
  1389. #endif
  1390. {
  1391.   unsigned int This;
  1392.  
  1393.   This = Min + (( Max - Min ) >> 1 );
  1394.   if( !DefineSymbol( SymbolText[ This ], ( long int )This, DirHead,
  1395.     &NullLocation ))
  1396.       RunError( False, CopySymbolWarning );
  1397.   if( This != Min )
  1398.     StoreSymbolList( SymbolText, Min, This - 1, DirHead );
  1399.   if( This != Max )
  1400.     StoreSymbolList( SymbolText, This + 1, Max, DirHead );
  1401. }
  1402.  
  1403. #if ANSI
  1404.   static PROC char *SplitLine( char *Result, char **Line, char AbortFlag )
  1405. #else
  1406.   static PROC char *SplitLine( Result, Line, AbortFlag )
  1407.   char *Result;
  1408.   char **Line;
  1409.   char AbortFlag;
  1410. #endif
  1411. {
  1412.   char *Start;
  1413.   char *Count;
  1414.   char *Store;
  1415.   int Level;
  1416.   char TextFlag;
  1417.   char Reading;
  1418.  
  1419.   Store = Result;
  1420.   *Store = NullChar;
  1421.   Level = 0;
  1422.   TextFlag = False;
  1423.   Reading = True;
  1424.   for( Start = NULL, Count = *Line; *Count; Count++ ) 
  1425.     if( *Count == RemarkChar )
  1426.       Count = NullString;
  1427.     else 
  1428.       if( isgraph( *Count ) && ( *Count != SeparatorChar )) {
  1429.         Start = Count;
  1430.         Count = NullString;
  1431.       }
  1432.   if( Start ) 
  1433.     for( Count = Start; *Count && ( Count < Start + ParamLength ); Count++ ) 
  1434.       if( *Count == TextChar ) {
  1435.         if( Count != Start )
  1436.           if( *( Count - 1 ) == TextChar ) 
  1437.             *( Store++ ) = TextChar;
  1438.         TextFlag = ( char )~TextFlag;
  1439.       } else
  1440.         if( TextFlag ) 
  1441.           *( Store++ ) = *Count;
  1442.         else
  1443.           switch( *Count ) {
  1444.             case SeparatorChar:
  1445.               if( !Level ) {
  1446.                 *Line = Count;
  1447.                 Reading = False;
  1448.                 Count = NullString;
  1449.               } else 
  1450.                 *( Store++ ) = *Count;
  1451.               break;
  1452.             case RemarkChar:
  1453.               *Line = NullString;
  1454.               Reading = False;
  1455.               Count = NullString;
  1456.               break;
  1457.             case StartChar:
  1458.               Level++;
  1459.               *( Store++ ) = *Count;
  1460.               break;
  1461.             case StopChar:
  1462.               Level--;
  1463.               *( Store++ ) = *Count;
  1464.               break;
  1465.             default:
  1466.               if( isgraph( *Count )) 
  1467.                 *( Store++ ) = ( char )toupper(( int )( *Count ));
  1468.               else
  1469.                 if( AbortFlag && ( !Level )) {
  1470.                   *Line = Count;
  1471.                   Reading = False;
  1472.                   Count = NullString;
  1473.                 } else
  1474.                   if( Store != Result )
  1475.                    if( *( Store - 1 ) != SpaceChar )
  1476.                      *( Store++ ) = SpaceChar; 
  1477.               break;
  1478.           }
  1479.   if( Reading )
  1480.     *Line = NullString;
  1481.   if( Store != Result )
  1482.     *( Store-- ) = NullChar;
  1483.   while( *Store == SpaceChar ) 
  1484.     if( Store > Result )
  1485.       *( Store-- ) = NullChar;
  1486.     else
  1487.       *Store = NullChar;
  1488.   return( Result );
  1489. }
  1490.  
  1491. #if ANSI
  1492.   static PROC void AlignWordBounds( void )
  1493. #else
  1494.   static PROC void AlignWordBounds()
  1495. #endif
  1496. {
  1497.   if( *AlignOnCond )
  1498.     Location.Addr = (( Location.Addr + 1 ) >> 1 ) << 1;
  1499.   if( Location.Addr > FinalAddress )
  1500.     FinalAddress = Location.Addr;
  1501.   if(( Location.Addr < StartAddress ) || ( Location.Addr > StopAddress ))
  1502.     RunError( True, BoundsError );
  1503. }
  1504.  
  1505. #if ANSI
  1506.   static PROC char ParamCheck( unsigned int Count, unsigned int Min,
  1507.     unsigned int Max )
  1508. #else
  1509.   static PROC char ParamCheck( Count, Min, Max )
  1510.   unsigned int Count;
  1511.   unsigned int Min;
  1512.   unsigned int Max;
  1513. #endif
  1514. {
  1515.   if(( Count < Min ) || ( Count > Max ))
  1516.     RunError( False, ParamCountWarning );
  1517.   if( Count >= Min )
  1518.     return( True );
  1519.   else
  1520.     return( False );
  1521. }
  1522.  
  1523. #if ANSI
  1524.   static PROC char RangeCheck( long int Value, long int Min, long int Max,
  1525.     char *Message )
  1526. #else
  1527.   static PROC char RangeCheck( Value, Min, Max, Message )
  1528.   long int Value;
  1529.   long int Min;
  1530.   long int Max;
  1531.   char *Message;
  1532. #endif
  1533. {
  1534.   if(( Value < Min ) || ( Value > Max )) {
  1535.     RunError( False, Message );
  1536.     return( True );
  1537.   } else
  1538.     return( False );
  1539. }
  1540.  
  1541. #if ANSI
  1542.   static PROC char DecodeOption( char *Option )
  1543. #else
  1544.   static PROC char DecodeOption( Option )
  1545.   char *Option;
  1546. #endif
  1547. {
  1548.   char Result;
  1549.  
  1550.   Result = True;
  1551.   if( !strcmp( Option, Chip8Name )) {
  1552.     *Chip8Cond = Defined;
  1553.     *Chip48Cond = Defined;
  1554.     *Super10Cond = UnDefined;
  1555.     *Super11Cond = UnDefined;
  1556.     *HpHeadCond = UnDefined;
  1557.     *HpAscCond = UnDefined;
  1558.     Result = False;
  1559.   }
  1560.   if( !strcmp( Option, Chip48Name )) {
  1561.     *Chip8Cond = UnDefined;
  1562.     *Chip48Cond = Defined;
  1563.     *Super10Cond = UnDefined;
  1564.     *Super11Cond = UnDefined;
  1565.     *HpHeadCond = Defined;
  1566.     Result = False;
  1567.   }
  1568.   if( !strcmp( Option, Super10Name )) {
  1569.     *Chip8Cond = UnDefined;
  1570.     *Chip48Cond = UnDefined;
  1571.     *Super10Cond = Defined;
  1572.     *Super11Cond = UnDefined;
  1573.     *HpHeadCond = Defined;
  1574.     Result = False;
  1575.   }
  1576.   if( !strcmp( Option, Super11Name )) {
  1577.     *Chip8Cond = UnDefined;
  1578.     *Chip48Cond = UnDefined;
  1579.     *Super10Cond = Defined;
  1580.     *Super11Cond = Defined;
  1581.     *HpHeadCond = Defined;
  1582.     Result = False;
  1583.   }
  1584.   if( !strcmp( Option, HpBinName )) {
  1585.     *HpHeadCond = Defined;
  1586.     *HpAscCond = UnDefined;
  1587.     Result = False;
  1588.   }
  1589.   if( !strcmp( Option, HpAscName )) {
  1590.     *HpHeadCond = Defined;
  1591.     *HpAscCond = Defined;
  1592.     Result = False;
  1593.   }
  1594.   if( !strcmp( Option, BinaryName )) {
  1595.     *HpHeadCond = UnDefined;
  1596.     *HpAscCond = UnDefined;
  1597.     Result = False;
  1598.   }
  1599.   if( !strcmp( Option, StringName )) {
  1600.     *HpHeadCond = UnDefined;
  1601.     *HpAscCond = Defined;
  1602.     Result = False;
  1603.   }
  1604.   return( Result );
  1605. }
  1606.  
  1607. #if ANSI
  1608.   static PROC unsigned int DecodeParameters( char **Line, ParamPointer *Head )
  1609. #else
  1610.   static PROC unsigned int DecodeParameters( Line, Head )
  1611.   char **Line;
  1612.   ParamPointer *Head;
  1613. #endif
  1614. {
  1615.   ParamString FoundWord;
  1616.   ParamPointer Param;
  1617.   ParamPointer Last;
  1618.   unsigned int Count;
  1619.  
  1620.   *Head = NULL;
  1621.   Count = 0;
  1622.   for( Last = NULL; **Line; )
  1623.     if( *SplitLine( FoundWord, Line, False )) {
  1624.       Param = ( ParamPointer )AssertSpace( &Space, sizeof( ParamRecord ));
  1625.       ClaimSpace( &Space, sizeof( ParamRecord ));
  1626.       Param->Param = ( char * )AssertSpace( &Space, sizeof( ParamString ));
  1627.       strcpy( Param->Param, FoundWord );
  1628.       ClaimSpace( &Space, ( unsigned int )( strlen( Param->Param ) + 1 ));
  1629.       Param->Next = NULL;
  1630.       if( Last )
  1631.         Last->Next = Param;
  1632.       else
  1633.         *Head = Param;
  1634.       Last = Param;
  1635.       Count++;
  1636.     }
  1637.   return( Count );
  1638. }
  1639.  
  1640. #if ANSI
  1641.   static PROC void DecodeDirective( unsigned int Token, char **Line,
  1642.     InstPointer *Head, SymbolPointer Dir, SymbolPointer *Symb,
  1643.     SymbolPointer *Cond )
  1644. #else
  1645.   static PROC void DecodeDirective( Token, Line, Head, Dir, Symb, Cond )
  1646.   unsigned int Token;
  1647.   char **Line;
  1648.   InstPointer *Head;
  1649.   SymbolPointer Dir;
  1650.   SymbolPointer *Symb;
  1651.   SymbolPointer *Cond;
  1652. #endif
  1653. {
  1654.   ParamPointer Params;
  1655.   InstPointer Inst;
  1656.   unsigned int Count;
  1657.  
  1658.   Count = DecodeParameters( Line, &Params );
  1659.   switch( Token ) {
  1660.     case ElseToken:
  1661.       ParamCheck( Count, 0, 0 );
  1662.       if( StackPoint == StackStart ) 
  1663.         RunError( False, MissingIfdefWarning );
  1664.       else 
  1665.         *StackPoint = ( char )~( *StackPoint );
  1666.       break;
  1667.     case EndifToken:
  1668.       ParamCheck( Count, 0, 0 );
  1669.       if( StackPoint <= StackStart ) 
  1670.         RunError( False, MissingIfdefWarning );
  1671.       else 
  1672.         StackPoint--;
  1673.       break;
  1674.     case IfdefToken:
  1675.     case IfundToken:
  1676.       if( ParamCheck( Count, 1, 1 )) {
  1677.         long int Value;
  1678.  
  1679.         if( !ResolveSymbol( Params->Param, &Value, *Cond, &NullLocation ))
  1680.           Value = 0L;
  1681.         if( Token == IfundToken )
  1682.           Value = ~Value;
  1683.         if( StackPoint >= StackStart + StackLength ) 
  1684.           RunError( True, NestedIfdefError );
  1685.         else 
  1686.           if( Value ) 
  1687.             *( ++StackPoint ) = True;
  1688.           else
  1689.             *( ++StackPoint ) = False;
  1690.       }
  1691.       break;
  1692.     default:
  1693.       if( *StackPoint ) {
  1694.         switch( Token ) {
  1695.           case WrongToken:
  1696.             RunError( False, InternalWarning );
  1697.             break;
  1698.           case AlignToken:
  1699.             if( ParamCheck( Count, 1, 1 )) 
  1700.               if( ResolveOption( Params->Param, AlignOnCond, AlignOnCond ))
  1701.                 RunError( False, NoOptionWarning );
  1702.             break;
  1703.           case DefineToken:
  1704.           case UndefToken:
  1705.             if( ParamCheck( Count, 1, 1 )) 
  1706.               if( Token == DefineToken )
  1707.                 DefineSymbol( Params->Param, Defined, Cond, &NullLocation );
  1708.               else
  1709.                 DefineSymbol( Params->Param, UnDefined, Cond,
  1710.                   &NullLocation );
  1711.             break;
  1712.           case EqualToken:
  1713.           case EquToken:
  1714.             if( !CurrentSymbol )
  1715.               RunError( False, MissingSymbolWarning );
  1716.             else 
  1717.               if( ParamCheck( Count, 1, 1 )) {
  1718.                 char *Expression;
  1719.  
  1720.                 Expression = ( char * )AssertSpace( &Space,
  1721.                   sizeof( ParamString ));
  1722.                 CurrentSymbol->Expr = strcpy( Expression, Params->Param );
  1723.                 ClaimSpace( &Space, ( unsigned int )
  1724.                   ( strlen( Expression ) + 1 ));
  1725.               }
  1726.             break;
  1727.           case DsToken:
  1728.             if( ParamCheck( Count, 1, 1 )) {
  1729.               char *FirstParam;
  1730.               long int Value;
  1731.  
  1732.               FirstParam = Params->Param;
  1733.               if( !ResolveExpression( &FirstParam, &Value, *Symb, &Location ))
  1734.                 RunError( False, UndefinedWarning );
  1735.               Location.Addr += Value;
  1736.             }
  1737.             break;
  1738.           case OptionToken:
  1739.             if( ParamCheck( Count, 1, 1 )) 
  1740.               if( DecodeOption( Params->Param ))
  1741.                 RunError( False, NoOptionWarning );
  1742.             break;
  1743.           case OrgToken:
  1744.             if( ParamCheck( Count, 1, 1 )) {
  1745.               char *FirstParam;
  1746.               long int Value;
  1747.  
  1748.               FirstParam = Params->Param;
  1749.               if( ResolveExpression( &FirstParam, &Value, *Symb, &Location ))
  1750.                 Location.Addr = Value;
  1751.               else
  1752.                 RunError( False, UndefinedWarning );
  1753.             }
  1754.             break;
  1755.           case IncludeToken:
  1756.             if( ParamCheck( Count, 1, 1 )) {
  1757.               FILE *StoreFile;
  1758.               LocRecord StoreLoc;
  1759.               char *IncludeName;
  1760.  
  1761.               StoreFile = InFile; 
  1762.               StoreLoc = Location;
  1763.               for( IncludeName = Params->Param; *IncludeName; IncludeName++ )
  1764.                 *IncludeName = ( char )tolower(( int )( *IncludeName ));
  1765.               IncludeName = ( char * )AssertSpace( &Space,
  1766.                 sizeof( LineString ));
  1767.               strcpy( IncludeName, Params->Param );
  1768.               ClaimSpace( &Space, ( unsigned int )
  1769.                 ( strlen( IncludeName ) + 1 ));
  1770.               InFile = fopen( IncludeName, "r" );
  1771.               if( !InFile )
  1772.                 RunError( True, NoSourceError );
  1773.               DecodeFile( IncludeName, Head, Dir, Symb, Cond );
  1774.               InFile = StoreFile;
  1775.               Location = StoreLoc;
  1776.               if( fprintf( stderr, "Reading: %s\n\n", Location.Name ) <= 0 )
  1777.                 RunError( True, FileWriteError );
  1778.               if( fprintf( ListFile, "Reading: %s\n\n", Location.Name ) <= 0 )
  1779.                 RunError( True, FileWriteError );
  1780.             }
  1781.             break;
  1782.           case EndToken:
  1783.             ParamCheck( Count, 0, 0 );
  1784.             /* The END directive is ignored */
  1785.             break;
  1786.           case UsedToken:
  1787.             if( ParamCheck( Count, 1, ListLength )) 
  1788.               if( ResolveOption( Params->Param, UsedYesCond, UsedOnCond )) {
  1789.                 ParamPointer Point;
  1790.                 long int Value;
  1791.       
  1792.                 for( Point = Params; Point; Point = Point->Next ) 
  1793.                   if( *XrefOnCond ) {
  1794.                     if( !ResolveSymbol( Point->Param, &Value, *Symb,
  1795.                       &Location ))
  1796.                         if( !Value )
  1797.                           RunError( False, NoSymbolWarning );
  1798.                   } else
  1799.                     if( !ResolveSymbol( Point->Param, &Value, *Symb,
  1800.                       &UsedLocation ))
  1801.                         if( !Value )
  1802.                           RunError( False, NoSymbolWarning );
  1803.               } else
  1804.                 if( Count > 1 )
  1805.                   RunError( False, ParamCountWarning );
  1806.             break;
  1807.           case XrefToken:
  1808.             if( ParamCheck( Count, 1, 1 )) 
  1809.               if( ResolveOption( Params->Param, XrefYesCond, XrefOnCond ))
  1810.                 RunError( False, NoOptionWarning );
  1811.             break;
  1812.           default:
  1813.             Inst = ( InstPointer )AssertSpace( &Space, sizeof( InstRecord ));
  1814.             ClaimSpace( &Space, sizeof( InstRecord ));
  1815.             Inst->Loc = Location;
  1816.             Inst->Token = Token;
  1817.             Inst->Count = Count;
  1818.             Inst->Params = Params;
  1819.             Inst->Next = NULL;
  1820.             if( *Head ) 
  1821.               ( *Head )->Next = Inst;
  1822.             else
  1823.               Instructions = Inst;
  1824.             *Head = Inst;
  1825.             switch( Token ) {
  1826.               case DbToken:
  1827.                 if( ParamCheck( Count, 1, ListLength ))
  1828.                   Location.Addr += Count;
  1829.                 break;
  1830.               case DwToken:
  1831.                 if( ParamCheck( Count, 1, ListLength ))
  1832.                   Location.Addr += Count * 2;
  1833.                 break;
  1834.               case DaToken:
  1835.                 if( ParamCheck( Count, 1, 1 ))
  1836.                   Location.Addr += strlen( Params->Param );
  1837.                 break;
  1838.               default:
  1839.                 Location.Addr += 2;
  1840.                 break;
  1841.             }
  1842.           break;
  1843.         }
  1844.       }
  1845.       break;
  1846.   }
  1847. }
  1848.  
  1849. #if ANSI
  1850.   static PROC void DecodeLine( char **Line, InstPointer *Head,
  1851.     SymbolPointer Dir, SymbolPointer *Symb, SymbolPointer *Cond )
  1852. #else
  1853.   static PROC void DecodeLine( Line, Head, Dir, Symb, Cond )
  1854.   char **Line;
  1855.   InstPointer *Head;
  1856.   SymbolPointer Dir;
  1857.   SymbolPointer *Symb;
  1858.   SymbolPointer *Cond;
  1859. #endif
  1860. {
  1861.   ParamString Split;
  1862.   long int Value;
  1863.  
  1864.   CurrentSymbol = NULL;
  1865.   while( **Line ) 
  1866.     if( *SplitLine( Split, Line, True )) 
  1867.       if( !ResolveSymbol( Split, &Value, Dir, &NullLocation )) {
  1868.         if( *StackPoint )
  1869.           if( CurrentSymbol ) {
  1870.             RunError( False, DualSymbolWarning );
  1871.             *Line = NullString;
  1872.           } else 
  1873.             if( !DefineSymbol( Split, Location.Addr, Symb, &Location ))
  1874.               RunError( False, CopySymbolWarning );
  1875.       } else {
  1876.         DecodeDirective(( unsigned int )Value, Line, Head, Dir, Symb, Cond );
  1877.         AlignWordBounds();
  1878.         *Line = NullString;
  1879.       }
  1880.   CurrentSymbol = NULL;
  1881. }
  1882.  
  1883. #if ANSI
  1884.   static PROC void DecodeFile( char *FileName, InstPointer *Head,
  1885.     SymbolPointer Dir, SymbolPointer *Symb, SymbolPointer *Cond )
  1886. #else
  1887.   static PROC void DecodeFile( FileName, Head, Dir, Symb, Cond )
  1888.   char *FileName;
  1889.   InstPointer *Head;
  1890.   SymbolPointer Dir;
  1891.   SymbolPointer *Symb;
  1892.   SymbolPointer *Cond;
  1893. #endif
  1894. {
  1895.   char *StoreStack;
  1896.   char *Line;
  1897.  
  1898.   StoreStack = StackPoint;
  1899.   if( fprintf( stderr, "Reading: %s\n\n", FileName ) <= 0 )
  1900.     RunError( True, FileWriteError );
  1901.   if( fprintf( ListFile, "Reading: %s\n\n", FileName ) <= 0 )
  1902.     RunError( True, FileWriteError );
  1903.   Location.Text = ( char * )AssertSpace( &Space, sizeof( LineString ));
  1904.   *( Location.Text ) = NullChar;
  1905.   Location.Name = FileName;
  1906.   Location.Line = 1;
  1907.   while( fgets( Location.Text, LineLength + 1, InFile )) {
  1908.     ClaimSpace( &Space, ( unsigned int )( strlen( Location.Text ) + 1 ));
  1909.     if( *XrefOnCond )
  1910.       Location.Xref = True;
  1911.     else
  1912.       Location.Xref = False;
  1913.     for( Line = Location.Text; *Line; Line++ )
  1914.       if( iscntrl( *Line ))
  1915.         *Line = SpaceChar;
  1916.     Line = Location.Text;
  1917.     DecodeLine( &Line, Head, Dir, Symb, Cond );
  1918.     Location.Text = ( char * )AssertSpace( &Space, sizeof( LineString ));
  1919.     *( Location.Text ) = NullChar;
  1920.     Location.Line++;
  1921.   }
  1922.   strcpy( Location.Text, EndOfFileMessage );
  1923.   ClaimSpace( &Space, ( unsigned int )( strlen( Location.Text ) + 1 ));
  1924.   if( StoreStack != StackPoint )
  1925.     RunError( False, CountDefineWarning );
  1926.   if( InFile )
  1927.     if( InFile != stdin )
  1928.       fclose( InFile );
  1929.   InFile = NULL;
  1930.   Location = NullLocation;
  1931. }
  1932.  
  1933. #if ANSI
  1934.   static PROC void EncodeNoneToken( InstPointer Inst, long int OpCode,
  1935.     long int *Ver10, long int *Ver11 )
  1936. #else
  1937.   static PROC void EncodeNoneToken( Inst, OpCode, Ver10, Ver11 )
  1938.   InstPointer Inst;
  1939.   long int OpCode;
  1940.   long int *Ver10;
  1941.   long int *Ver11;
  1942. #endif
  1943. {
  1944.   ParamCheck( Inst->Count, 0, 0 );
  1945.   /* Generate instruction anyway */
  1946.   if( !( *Ver11 ))
  1947.     RunError( False, NeedsSuper11Warning );
  1948.   if( !( *Ver10 ))
  1949.     RunError( False, NeedsSuper10Warning );
  1950.   Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  1951.     (( OpCode & 0xff00L ) >> 8 );
  1952.   Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  1953.     ( OpCode & 0xffL );
  1954.   ListInstruction( Inst->Loc.Addr, 2, Inst );
  1955. }
  1956.  
  1957. #if ANSI
  1958.   static PROC void EncodeValToken( InstPointer Inst, long int OpCode,
  1959.     long int Limit, SymbolPointer Symb, long int *Ver8, long int *Ver11 )
  1960. #else
  1961.   static PROC void EncodeValToken( Inst, OpCode, Limit, Symb, Ver8, Ver11 )
  1962.   InstPointer Inst;
  1963.   long int OpCode;
  1964.   long int Limit;
  1965.   SymbolPointer Symb;
  1966.   long int *Ver8; 
  1967.   long int *Ver11;
  1968. #endif
  1969. {
  1970.   long int Value;
  1971.  
  1972.   Value = 0L;
  1973.   if( ParamCheck( Inst->Count, 1, 1 )) {
  1974.     char *FirstParam;
  1975.  
  1976.     FirstParam = Inst->Params->Param;
  1977.     if( !ResolveExpression( &FirstParam, &Value, Symb, &( Inst->Loc )))
  1978.       RunError( False, UndefinedWarning );
  1979.   }
  1980.   if( RangeCheck( Value, 0L, Limit, RangeWarning ))
  1981.     Value &= Limit;
  1982.   if( !( *Ver11 ))
  1983.     RunError( False, NeedsSuper11Warning );
  1984.   if( !( *Ver8 ))
  1985.     RunError( False, NeedsChip8Warning );
  1986.   Value |= OpCode;
  1987.   Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  1988.     (( Value & 0xff00L ) >> 8 );
  1989.   Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  1990.     ( Value & 0xffL );
  1991.   ListInstruction( Inst->Loc.Addr, 2, Inst );
  1992. }
  1993.  
  1994. #if ANSI
  1995.   static PROC void EncodeRegToken( InstPointer Inst, long int OpCode,
  1996.     SymbolPointer Reg )
  1997. #else
  1998.   static PROC void EncodeRegToken( Inst, OpCode, Reg )
  1999.   InstPointer Inst;
  2000.   long int OpCode;
  2001.   SymbolPointer Reg;
  2002. #endif
  2003. {
  2004.   long int RegX;
  2005.  
  2006.   RegX = ( long int )V0Reg;
  2007.   if( ParamCheck( Inst->Count, 1, 1 )) {
  2008.     if( ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation ))
  2009.       RegX -= V0Reg;
  2010.     else
  2011.       RunError( False, NoRegisterWarning );
  2012.   }
  2013.   if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2014.     RegX = 0L;
  2015.   RegX = OpCode | ( RegX << 8 );
  2016.   Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2017.     (( RegX & 0xff00L ) >> 8 );
  2018.   Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2019.     ( RegX & 0xffL );
  2020.   ListInstruction( Inst->Loc.Addr, 2, Inst );
  2021. }
  2022.  
  2023. #if ANSI
  2024.   static PROC void EncodeRegValToken( InstPointer Inst, long int OpCode,
  2025.     SymbolPointer Reg, SymbolPointer Symb )
  2026. #else
  2027.   static PROC void EncodeRegValToken( Inst, OpCode, Reg, Symb )
  2028.   InstPointer Inst;
  2029.   long int OpCode;
  2030.   SymbolPointer Reg;
  2031.   SymbolPointer Symb;
  2032. #endif
  2033. {
  2034.   long int RegX;
  2035.   long int Value;
  2036.  
  2037.   RegX = ( long int )V0Reg;
  2038.   Value = 0L;
  2039.   if( Inst->Count >= 1 ) 
  2040.     if( ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation ))
  2041.       RegX -= V0Reg;
  2042.     else
  2043.       RunError( False, NoRegisterWarning );
  2044.   if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2045.     RegX = 0L;
  2046.   if( ParamCheck( Inst->Count, 2, 2 )) {
  2047.     char *SecondParam;
  2048.  
  2049.     SecondParam = Inst->Params->Next->Param;
  2050.     if( !ResolveExpression( &SecondParam, &Value, Symb, &( Inst->Loc )))
  2051.       RunError( False, UndefinedWarning );
  2052.   }
  2053.   if( RangeCheck( Value, 0L, ByteMask, RangeWarning ))
  2054.     Value &= ByteMask;
  2055.   Value |= OpCode | ( RegX << 8 );
  2056.   Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2057.     (( Value & 0xff00L ) >> 8 );
  2058.   Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2059.     ( Value & 0xffL );
  2060.   ListInstruction( Inst->Loc.Addr, 2, Inst );
  2061. }
  2062.  
  2063. #if ANSI
  2064.   static PROC void EncodeRegRegToken( InstPointer Inst, long int OpCode,
  2065.     unsigned int Min, SymbolPointer Reg )
  2066. #else
  2067.   static PROC void EncodeRegRegToken( Inst, OpCode, Min, Reg )
  2068.   InstPointer Inst;
  2069.   long int OpCode;
  2070.   unsigned int Min;
  2071.   SymbolPointer Reg;
  2072. #endif
  2073. {
  2074.   long int RegX;
  2075.   long int RegY;
  2076.  
  2077.   RegX = ( long int )V0Reg;
  2078.   RegY = 0L;
  2079.   if( ParamCheck( Inst->Count, Min, 2 )) 
  2080.     if( ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation ))
  2081.       RegX -= V0Reg;
  2082.     else
  2083.       RunError( False, NoRegisterWarning );
  2084.   if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2085.     RegX = 0L;
  2086.   if( Inst->Count >= 2 ) 
  2087.     if( ResolveSymbol( Inst->Params->Next->Param, &RegY, Reg, &NullLocation ))
  2088.       RegY -= V0Reg;
  2089.     else
  2090.       RunError( False, NoRegisterWarning );
  2091.   if( RangeCheck( RegY, 0L, NibbleMask, BadRegisterWarning ))
  2092.     RegY = 0L;
  2093.   RegX = OpCode | ( RegX << 8 ) | ( RegY << 4 );
  2094.   Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2095.     (( RegX & 0xff00L ) >> 8 );
  2096.   Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2097.     ( RegX & 0xffL );
  2098.   ListInstruction( Inst->Loc.Addr, 2, Inst );
  2099. }
  2100.  
  2101. #if ANSI
  2102.   static PROC void EncodeRegRegOrValToken( InstPointer Inst, long int OpCode1,
  2103.     long int OpCode2, SymbolPointer Reg, SymbolPointer Symb )
  2104. #else
  2105.   static PROC void EncodeRegRegOrValToken( Inst, OpCode1, OpCode2, Reg, Symb )
  2106.   InstPointer Inst;
  2107.   long int OpCode1;
  2108.   long int OpCode2;
  2109.   SymbolPointer Reg;
  2110.   SymbolPointer Symb;
  2111. #endif
  2112. {
  2113.   long int RegX;
  2114.   long int RegY;
  2115.   long int Value;
  2116.  
  2117.   RegX = ( long int )V0Reg;
  2118.   RegY = ( long int )V0Reg;
  2119.   Value = 0L;
  2120.   if( Inst->Count >= 1 ) 
  2121.     if( ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation ))
  2122.       RegX -= V0Reg;
  2123.     else
  2124.       RunError( False, NoRegisterWarning );
  2125.   if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2126.     RegX = 0L;
  2127.   if( ParamCheck( Inst->Count, 2, 2 ))
  2128.     if( ResolveSymbol( Inst->Params->Next->Param, &RegY, Reg,
  2129.       &NullLocation )) {
  2130.         RegY -= V0Reg;
  2131.         if( RangeCheck( RegY, 0L, NibbleMask, BadRegisterWarning ))
  2132.           RegY = 0L;
  2133.         Value = OpCode1 | ( RegX << 8 ) | ( RegY << 4 );
  2134.         Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2135.           (( Value & 0xff00L ) >> 8 );
  2136.         Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2137.           ( Value & 0xffL );
  2138.         ListInstruction( Inst->Loc.Addr, 2, Inst );
  2139.       } else {
  2140.         char *SecondParam;
  2141.  
  2142.         SecondParam = Inst->Params->Next->Param; 
  2143.         if( !ResolveExpression( &SecondParam, &Value, Symb, &( Inst->Loc )))
  2144.           RunError( False, UndefinedWarning );
  2145.         if( RangeCheck( Value, 0L, ByteMask, RangeWarning ))
  2146.           Value &= ByteMask;
  2147.         Value |= OpCode2 | ( RegX << 8 );
  2148.         Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2149.           (( Value & 0xff00L ) >> 8 );
  2150.         Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2151.           ( Value & 0xffL );
  2152.         ListInstruction( Inst->Loc.Addr, 2, Inst );
  2153.       }
  2154. }
  2155.  
  2156. #if ANSI
  2157.   static PROC void EncodeDrwToken( InstPointer Inst, long int OpCode,
  2158.     SymbolPointer Reg, SymbolPointer Symb )
  2159. #else
  2160.   static PROC void EncodeDrwToken( Inst, OpCode, Reg, Symb )
  2161.   InstPointer Inst;
  2162.   long int OpCode;
  2163.   SymbolPointer Reg;
  2164.   SymbolPointer Symb;
  2165. #endif
  2166. {
  2167.   long int RegX;
  2168.   long int RegY;
  2169.   long int Value;
  2170.  
  2171.   RegX = ( long int )V0Reg;
  2172.   RegY = ( long int )V0Reg;
  2173.   Value = 0L;
  2174.   if( Inst->Count >= 1 ) 
  2175.     if( ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation ))
  2176.       RegX -= V0Reg;
  2177.     else
  2178.       RunError( False, NoRegisterWarning );
  2179.   if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2180.     RegX = 0L;
  2181.   if( Inst->Count >= 2 ) 
  2182.     if( ResolveSymbol( Inst->Params->Next->Param, &RegY, Reg, &NullLocation ))
  2183.       RegY -= V0Reg;
  2184.     else
  2185.       RunError( False, NoRegisterWarning );
  2186.   if( RangeCheck( RegY, 0L, NibbleMask, BadRegisterWarning ))
  2187.     RegY = 0L;
  2188.   if( ParamCheck( Inst->Count, 3, 3 )) {
  2189.     char *ThirdParam;
  2190.  
  2191.     ThirdParam = Inst->Params->Next->Next->Param;
  2192.     if( !ResolveExpression( &ThirdParam, &Value, Symb, &( Inst->Loc )))
  2193.       RunError( False, UndefinedWarning );
  2194.   }
  2195.   if( RangeCheck( Value, 0L, NibbleMask, RangeWarning ))
  2196.     Value &= NibbleMask;
  2197.   if(( Value == 0L ) && !( *Super10Cond ))
  2198.     RunError( False, NeedsSuper10Warning );
  2199.   Value |= OpCode | ( RegX << 8 ) | ( RegY << 4 );
  2200.   Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2201.     (( Value & 0xff00L ) >> 8 );
  2202.   Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2203.     ( Value & 0xffL );
  2204.   ListInstruction( Inst->Loc.Addr, 2, Inst );
  2205. }
  2206.  
  2207. #if ANSI
  2208.   static PROC void EncodeAddToken( InstPointer Inst, SymbolPointer Reg,
  2209.     SymbolPointer Symb )
  2210. #else
  2211.   static PROC void EncodeAddToken( Inst, Reg, Symb )
  2212.   InstPointer Inst;
  2213.   SymbolPointer Reg;
  2214.   SymbolPointer Symb;
  2215. #endif
  2216. {
  2217.   long int RegX;
  2218.   long int RegY;
  2219.   long int Value;
  2220.  
  2221.   RegX = ( long int )V0Reg;
  2222.   RegY = ( long int )V0Reg;
  2223.   Value = 0L;
  2224.   if( Inst->Count >= 1 ) 
  2225.     if( !ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation )) {
  2226.       RegX = ( long int )V0Reg;
  2227.       RunError( False, NoRegisterWarning );
  2228.     }
  2229.   if( RegX == ( long int )IReg ) {
  2230.     if( ParamCheck( Inst->Count, 2, 2 )) 
  2231.       if( ResolveSymbol( Inst->Params->Next->Param, &RegX, Reg,
  2232.         &NullLocation ))
  2233.           RegX -= V0Reg;
  2234.       else
  2235.         RunError( False, NoRegisterWarning );
  2236.     if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2237.       RegX = 0L;
  2238.     Value = 0xf01eL | ( RegX << 8 );
  2239.     Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2240.       (( Value & 0xff00L ) >> 8 );
  2241.     Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2242.       ( Value & 0xffL );
  2243.     ListInstruction( Inst->Loc.Addr, 2, Inst );
  2244.   } else {
  2245.     RegX -= V0Reg;
  2246.     if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2247.       RegX = 0L;
  2248.     if( ParamCheck( Inst->Count, 2, 2 ))
  2249.       if( ResolveSymbol( Inst->Params->Next->Param, &RegY, Reg,
  2250.         &NullLocation )) {
  2251.           RegY -= V0Reg;
  2252.           if( RangeCheck( RegY, 0L, NibbleMask, BadRegisterWarning ))
  2253.             RegY = 0L;
  2254.           Value = 0x8004L | ( RegX << 8 ) | ( RegY << 4 );
  2255.           Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2256.             (( Value & 0xff00L ) >> 8 );
  2257.           Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2258.             ( Value & 0xffL );
  2259.           ListInstruction( Inst->Loc.Addr, 2, Inst );
  2260.         } else {
  2261.           char *SecondParam;
  2262.  
  2263.           SecondParam = Inst->Params->Next->Param;
  2264.           if( !ResolveExpression( &SecondParam, &Value, Symb, &( Inst->Loc )))
  2265.             RunError( False, UndefinedWarning );
  2266.           if( RangeCheck( Value, 0L, ByteMask, RangeWarning ))
  2267.             Value &= ByteMask;
  2268.           Value |= 0x7000L | ( RegX << 8 );
  2269.           Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2270.             (( Value & 0xff00L ) >> 8 );
  2271.           Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2272.             ( Value & 0xffL );
  2273.           ListInstruction( Inst->Loc.Addr, 2, Inst );
  2274.         }
  2275.   }
  2276. }
  2277.  
  2278. #if ANSI
  2279.   static PROC void EncodeJpToken( InstPointer Inst, SymbolPointer Reg,
  2280.     SymbolPointer Symb )
  2281. #else
  2282.   static PROC void EncodeJpToken( Inst, Reg, Symb )
  2283.   InstPointer Inst;
  2284.   SymbolPointer Reg;
  2285.   SymbolPointer Symb;
  2286. #endif
  2287. {
  2288.   long int RegX;
  2289.   long int Addr;
  2290.  
  2291.   RegX = ( long int )V0Reg;
  2292.   Addr = ( long int )V0Reg;
  2293.   if( ParamCheck( Inst->Count, 1, 2 ))
  2294.     if( ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation )) {
  2295.       if( RegX != V0Reg )
  2296.         RunError( False, BadRegisterWarning );
  2297.       if( Inst->Count == 1 )
  2298.         RunError( False, ParamCountWarning );
  2299.       else {
  2300.         char *SecondParam;
  2301.  
  2302.         SecondParam = Inst->Params->Next->Param;
  2303.         if( ResolveExpression( &SecondParam , &Addr, Symb, &( Inst->Loc )))
  2304.           RunError( False, UndefinedWarning );
  2305.       }
  2306.       if( RangeCheck( Addr, 0L, AddrMask, RangeWarning ))
  2307.         Addr &= AddrMask;
  2308.       Addr |= 0xb000L;
  2309.       Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2310.         (( Addr & 0xff00L ) >> 8 );
  2311.       Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2312.         ( Addr & 0xffL );
  2313.       ListInstruction( Inst->Loc.Addr, 2, Inst );
  2314.     } else {
  2315.       char *FirstParam;
  2316.  
  2317.       FirstParam = Inst->Params->Param;
  2318.       if( !ResolveExpression( &FirstParam, &Addr, Symb, &( Inst->Loc )))
  2319.         RunError( False, UndefinedWarning );
  2320.       if( Inst->Count == 2 )
  2321.         RunError( False, ParamCountWarning );
  2322.       if( RangeCheck( Addr, 0L, AddrMask, RangeWarning ))
  2323.         Addr &= AddrMask;
  2324.       Addr |= 0x1000L;
  2325.       Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2326.         (( Addr & 0xff00L ) >> 8 );
  2327.       Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2328.         ( Addr & 0xffL );
  2329.       ListInstruction( Inst->Loc.Addr, 2, Inst );
  2330.     }
  2331. }
  2332.  
  2333. #if ANSI
  2334.   static PROC void EncodeLdToken( InstPointer Inst, SymbolPointer Reg,
  2335.     SymbolPointer Symb )
  2336. #else
  2337.   static PROC void EncodeLdToken( Inst, Reg, Symb )
  2338.   InstPointer Inst;
  2339.   SymbolPointer Reg;
  2340.   SymbolPointer Symb;
  2341. #endif
  2342. {
  2343.   long int RegX;
  2344.   long int RegY;
  2345.   long int Value;
  2346.   char RegFlag;
  2347.  
  2348.   RegX = ( long int )V0Reg;
  2349.   RegY = ( long int )V0Reg;
  2350.   Value = 0L;
  2351.   RegFlag = True;
  2352.   if( Inst->Count >= 1 ) 
  2353.     if( !ResolveSymbol( Inst->Params->Param, &RegX, Reg, &NullLocation )) {
  2354.       RegX = ( long int )V0Reg;
  2355.       RunError( False, NoRegisterWarning );
  2356.     }
  2357.   switch( RegX ) {
  2358.     case BReg:
  2359.     case DtReg:
  2360.     case FReg:
  2361.     case HfReg:
  2362.     case LfReg:
  2363.     case RReg:
  2364.     case StReg:
  2365.     case IiReg:
  2366.       RegY = RegX;
  2367.       RegX = ( long int )V0Reg;
  2368.       if( ParamCheck( Inst->Count, 2, 2 )) 
  2369.         if( ResolveSymbol( Inst->Params->Next->Param, &RegX, Reg,
  2370.           &NullLocation ))
  2371.             RegX -= V0Reg;
  2372.         else
  2373.           RunError( False, NoRegisterWarning );
  2374.       if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2375.         RegX = 0L;
  2376.       switch( RegY ) {
  2377.         case BReg:
  2378.           Value = 0xf033L | ( RegX << 8 );
  2379.           break;
  2380.         case DtReg:
  2381.           Value = 0xf015L | ( RegX << 8 );
  2382.           break;
  2383.         case FReg:
  2384.           if( !( *Chip48Cond ))
  2385.             RunError( False, NeedsChip48Warning );
  2386.           Value = 0xf029L | ( RegX << 8 );
  2387.           break;
  2388.         case HfReg:
  2389.           if( !( *Super10Cond ))
  2390.             RunError( False, NeedsSuper10Warning );
  2391.           Value = 0xf030L | ( RegX << 8 );
  2392.           break;
  2393.         case LfReg:
  2394.           if( !( *Super10Cond ))
  2395.             RunError( False, NeedsSuper10Warning );
  2396.           Value = 0xf029L | ( RegX << 8 );
  2397.           break;
  2398.         case RReg:
  2399.           if( RangeCheck( RegX, 0L, 7L, BadRegisterWarning ))
  2400.             RegX = 0L;
  2401.           if( !( *Super10Cond ))
  2402.             RunError( False, NeedsSuper10Warning );
  2403.           Value = 0xf075L | ( RegX << 8 );
  2404.           break;
  2405.         case StReg:
  2406.           Value = 0xf018L | ( RegX << 8 );
  2407.           break;
  2408.         case IiReg:
  2409.           Value = 0xf055L | ( RegX << 8 );
  2410.           break;
  2411.         default:
  2412.           RunError( False, InternalWarning );
  2413.           break;
  2414.       }
  2415.       Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2416.         (( Value & 0xff00L ) >> 8 );
  2417.       Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2418.         ( Value & 0xffL );
  2419.       ListInstruction( Inst->Loc.Addr, 2, Inst );
  2420.       break;
  2421.     case IReg:
  2422.       if( ParamCheck( Inst->Count, 2, 2 )) {
  2423.         char *SecondParam;
  2424.  
  2425.         SecondParam = Inst->Params->Next->Param;
  2426.         if( !ResolveExpression( &SecondParam, &Value, Symb, &( Inst->Loc )))
  2427.           RunError( False, UndefinedWarning );
  2428.       }
  2429.       if( RangeCheck( Value, 0L, AddrMask, RangeWarning ))
  2430.         Value &= AddrMask;
  2431.       Value |= 0xa000L;
  2432.       Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2433.         (( Value & 0xff00L ) >> 8 );
  2434.       Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2435.         ( Value & 0xffL );
  2436.       ListInstruction( Inst->Loc.Addr, 2, Inst );
  2437.       break;
  2438.     default:
  2439.       RegX -= V0Reg;
  2440.       if( RangeCheck( RegX, 0L, NibbleMask, BadRegisterWarning ))
  2441.         RegX = 0L;
  2442.       if( ParamCheck( Inst->Count, 2, 2 ))
  2443.         RegFlag = ResolveSymbol( Inst->Params->Next->Param, &RegY, Reg,
  2444.           &NullLocation );
  2445.       if( RegFlag ) 
  2446.         switch( RegY ) {
  2447.           case DtReg:
  2448.             Value = 0xf007L | ( RegX << 8 );
  2449.             Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2450.               (( Value & 0xff00L ) >> 8 );
  2451.             Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2452.               ( Value & 0xffL );
  2453.             ListInstruction( Inst->Loc.Addr, 2, Inst );
  2454.             break;
  2455.           case KReg:
  2456.             Value = 0xf00aL | ( RegX << 8 );
  2457.             Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2458.               (( Value & 0xff00L ) >> 8 );
  2459.             Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2460.               ( Value & 0xffL );
  2461.             ListInstruction( Inst->Loc.Addr, 2, Inst );
  2462.             break;
  2463.           case RReg:
  2464.             if( RangeCheck( RegX, 0L, 7L, BadRegisterWarning ))
  2465.               RegX = 0L;
  2466.             if( !( *Super10Cond ))
  2467.               RunError( False, NeedsSuper10Warning );
  2468.             Value = 0xf085L | ( RegX << 8 );
  2469.             Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2470.               (( Value & 0xff00L ) >> 8 );
  2471.             Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2472.               ( Value & 0xffL );
  2473.             ListInstruction( Inst->Loc.Addr, 2, Inst );
  2474.             break;
  2475.           case IiReg:
  2476.             Value = 0xf065L | ( RegX << 8 );
  2477.             Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2478.               (( Value & 0xff00L ) >> 8 );
  2479.             Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2480.               ( Value & 0xffL );
  2481.             ListInstruction( Inst->Loc.Addr, 2, Inst );
  2482.             break;
  2483.           default:
  2484.             RegY -= V0Reg;
  2485.             if( RangeCheck( RegY, 0L, NibbleMask, BadRegisterWarning ))
  2486.               RegY = 0L;
  2487.             Value = 0x8000L | ( RegX << 8 ) | ( RegY << 4 );
  2488.             Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2489.               (( Value & 0xff00L ) >> 8 );
  2490.             Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2491.               ( Value & 0xffL );
  2492.             ListInstruction( Inst->Loc.Addr, 2, Inst );
  2493.             break;
  2494.         }
  2495.       else {
  2496.         if( Inst->Count >= 2 ) {
  2497.           char *SecondParam;
  2498.  
  2499.           SecondParam = Inst->Params->Next->Param;
  2500.           if( !ResolveExpression( &SecondParam, &Value, Symb, &( Inst->Loc )))
  2501.             RunError( False, UndefinedWarning );
  2502.         }
  2503.         if( RangeCheck( Value, 0L, ByteMask, RangeWarning ))
  2504.           Value &= ByteMask;
  2505.         Value |= 0x6000L | ( RegX << 8 );
  2506.         Memory[ Inst->Loc.Addr - StartAddress ] = ( unsigned char )
  2507.           (( Value & 0xff00L ) >> 8 );
  2508.         Memory[ Inst->Loc.Addr - StartAddress + 1 ] = ( unsigned char )
  2509.           ( Value & 0xffL );
  2510.         ListInstruction( Inst->Loc.Addr, 2, Inst );
  2511.       }
  2512.       break;
  2513.   }
  2514. }
  2515.  
  2516. #if ANSI
  2517.   static PROC void EncodeDaToken( InstPointer Inst )
  2518. #else
  2519.   static PROC void EncodeDaToken( Inst )
  2520.   InstPointer Inst;
  2521. #endif
  2522. {
  2523.   char *Param;
  2524.   char *This;
  2525.   long int Store;
  2526.  
  2527.   Param = NullString;
  2528.   if( Inst->Count >= 1 )
  2529.     Param = Inst->Params->Param;
  2530.   Store = Inst->Loc.Addr - StartAddress;
  2531.   for( This = Param ; *This; This++ )
  2532.     Memory[ Store++ ] = *This;
  2533.   ListInstruction( Inst->Loc.Addr, ( unsigned int )strlen( Param ), Inst );
  2534. }
  2535.  
  2536. #if ANSI
  2537.   static PROC void EncodeDbToken( InstPointer Inst, SymbolPointer Symb )
  2538. #else
  2539.   static PROC void EncodeDbToken( Inst, Symb )
  2540.   InstPointer Inst;
  2541.   SymbolPointer Symb;
  2542. #endif
  2543. {
  2544.   ParamPointer Param;
  2545.   char *LoopParam;
  2546.   long int Value;
  2547.   unsigned int This;
  2548.  
  2549.   This = 0;
  2550.   Value = 0L;
  2551.   for( Param = Inst->Params; Param; Param = Param->Next ) {
  2552.     LoopParam = Param->Param; 
  2553.     if( !ResolveExpression( &LoopParam, &Value, Symb, &( Inst->Loc )))
  2554.       RunError( False, UndefinedWarning );
  2555.     if( RangeCheck( Value, 0L, ByteMask, RangeWarning ))
  2556.       Value &= ByteMask;
  2557.     Memory[ Inst->Loc.Addr + ( This++ ) - StartAddress ] = ( unsigned char )
  2558.       Value;
  2559.   }
  2560.   ListInstruction( Inst->Loc.Addr, Inst->Count, Inst );
  2561. }
  2562.  
  2563. #if ANSI
  2564.   static PROC void EncodeDwToken( InstPointer Inst, SymbolPointer Symb )
  2565. #else
  2566.   static PROC void EncodeDwToken( Inst, Symb )
  2567.   InstPointer Inst;
  2568.   SymbolPointer Symb;
  2569. #endif
  2570. {
  2571.   ParamPointer Param;
  2572.   char *LoopParam;
  2573.   long int Value;
  2574.   unsigned int This;
  2575.  
  2576.   This = 0;
  2577.   Value = 0L;
  2578.   for( Param = Inst->Params; Param; Param = Param->Next ) {
  2579.     LoopParam = Param->Param;
  2580.     if( !ResolveExpression( &LoopParam, &Value, Symb, &( Inst->Loc )))
  2581.       RunError( False, UndefinedWarning );
  2582.     if( RangeCheck( Value, 0L, WordMask, RangeWarning ))
  2583.       Value &= WordMask;
  2584.     Memory[ Inst->Loc.Addr + ( This++ ) - StartAddress ] = ( unsigned char )
  2585.       (( Value & 0xff00L ) >> 8 );
  2586.     Memory[ Inst->Loc.Addr + ( This++ ) - StartAddress ] = ( unsigned char )
  2587.       ( Value & 0xffL );
  2588.   }
  2589.   ListInstruction( Inst->Loc.Addr, Inst->Count * 2, Inst );
  2590. }
  2591.  
  2592. #if ANSI
  2593.   static PROC void EncodeInstruction( InstPointer Inst, SymbolPointer Reg,
  2594.     SymbolPointer Symb )
  2595. #else
  2596.   static PROC void EncodeInstruction( Inst, Reg, Symb )
  2597.   InstPointer Inst;
  2598.   SymbolPointer Reg;
  2599.   SymbolPointer Symb;
  2600. #endif
  2601. {
  2602.   switch( Inst->Token ) {
  2603.     case AddToken:
  2604.       EncodeAddToken( Inst, Reg, Symb );
  2605.       break;
  2606.     case AndToken:
  2607.       EncodeRegRegToken( Inst, 0x8002L, 2, Reg );
  2608.       break;
  2609.     case CallToken:
  2610.       EncodeValToken( Inst, 0x2000L, AddrMask, Symb, &DefinedValue,
  2611.         &DefinedValue );
  2612.       break;
  2613.     case ClsToken:
  2614.       EncodeNoneToken( Inst, 0x00e0L, &DefinedValue, &DefinedValue );
  2615.       break;
  2616.     case DaToken:
  2617.       EncodeDaToken( Inst );
  2618.       break;
  2619.     case DbToken:
  2620.       EncodeDbToken( Inst, Symb );
  2621.       break;
  2622.     case DrwToken:
  2623.       EncodeDrwToken( Inst, 0xd000L, Reg, Symb );
  2624.       break;
  2625.     case DwToken:
  2626.       EncodeDwToken( Inst, Symb );
  2627.       break;
  2628.     case ExitToken:
  2629.       EncodeNoneToken( Inst, 0x00fdL, Super10Cond, &DefinedValue );
  2630.       break;
  2631.     case HighToken:
  2632.       EncodeNoneToken( Inst, 0x00ffL, Super10Cond, &DefinedValue );
  2633.       break;
  2634.     case JpToken:
  2635.       EncodeJpToken( Inst, Reg, Symb );
  2636.       break;
  2637.     case LdToken:
  2638.       EncodeLdToken( Inst, Reg, Symb );
  2639.       break;
  2640.     case LowToken:
  2641.       EncodeNoneToken( Inst, 0x00feL, Super10Cond, &DefinedValue );
  2642.       break;
  2643.     case OrToken:
  2644.       EncodeRegRegToken( Inst, 0x8001L, 2, Reg );
  2645.       break;
  2646.     case RetToken:
  2647.       EncodeNoneToken( Inst, 0x00eeL, &DefinedValue, &DefinedValue );
  2648.       break;
  2649.     case RndToken:
  2650.       EncodeRegValToken( Inst, 0xc000L, Reg, Symb );
  2651.       break;
  2652.     case ScdToken:
  2653.       EncodeValToken( Inst, 0x00c0L, NibbleMask, Symb, &DefinedValue,
  2654.         Super11Cond );
  2655.       break;
  2656.     case SclToken:
  2657.       EncodeNoneToken( Inst, 0x00fcL, &DefinedValue, Super11Cond );
  2658.       break;
  2659.     case ScrToken:
  2660.       EncodeNoneToken( Inst, 0x00fbL, &DefinedValue, Super11Cond );
  2661.       break;
  2662.     case SeToken:
  2663.       EncodeRegRegOrValToken( Inst, 0x5000L, 0x3000L, Reg, Symb );
  2664.       break;
  2665.     case ShlToken:
  2666.       EncodeRegRegToken( Inst, 0x800eL, 1, Reg );
  2667.       break;
  2668.     case ShrToken:
  2669.       EncodeRegRegToken( Inst, 0x8006L, 1, Reg );
  2670.       break;
  2671.     case SknpToken:
  2672.       EncodeRegToken( Inst, 0xe0a1L, Reg );
  2673.       break;
  2674.     case SkpToken:
  2675.       EncodeRegToken( Inst, 0xe09eL, Reg );
  2676.       break;
  2677.     case SneToken:
  2678.       EncodeRegRegOrValToken( Inst, 0x9000L, 0x4000L, Reg, Symb );
  2679.       break;
  2680.     case SubToken:
  2681.       EncodeRegRegToken( Inst, 0x8005L, 2, Reg );
  2682.       break;
  2683.     case SubnToken:
  2684.       EncodeRegRegToken( Inst, 0x8007L, 2, Reg );
  2685.       break;
  2686.     case SysToken:
  2687.       EncodeValToken( Inst, 0x2000L, AddrMask, Symb, Chip8Cond,
  2688.         &DefinedValue );
  2689.       break;
  2690.     case XorToken:
  2691.       EncodeRegRegToken( Inst, 0x8003L, 2, Reg );
  2692.       break;
  2693.     default:
  2694.       RunError( False, InternalWarning );
  2695.       break;
  2696.   }
  2697. }
  2698.  
  2699. #if ANSI
  2700.   static PROC void EncodeMemory( InstPointer Inst, SymbolPointer Reg,
  2701.     SymbolPointer Symb, SymbolPointer Cond )
  2702. #else
  2703.   static PROC void EncodeMemory( Inst, Reg, Symb, Cond )
  2704.   InstPointer Inst;
  2705.   SymbolPointer Reg;
  2706.   SymbolPointer Symb;
  2707.   SymbolPointer Cond;
  2708. #endif
  2709. {
  2710.   long int Count;
  2711.  
  2712.   if( fprintf( ListFile, "-----   *INSTRUCTIONS*   -----\n\n" ) <= 0 )
  2713.     RunError( True, FileWriteError );
  2714.   for( Count = StartAddress; Count <= StopAddress; Count++ )
  2715.     Memory[ Count - StartAddress ] = 0;
  2716.   while( Inst ) {
  2717.     InstPoint = Inst;
  2718.     EncodeInstruction( Inst, Reg, Symb );
  2719.     Inst = Inst->Next;
  2720.   }
  2721.   InstPoint = NULL;
  2722.   if( fprintf( ListFile, "\n-----   *SYMBOLS*   -----\n\n" ) <= 0 )
  2723.     RunError( True, FileWriteError );
  2724.   ListSymbols( Symb );
  2725.   if( fprintf( ListFile, "\n-----   *CONDITIONS*   -----\n\n" ) <= 0 )
  2726.     RunError( True, FileWriteError );
  2727.   ListDefines( Cond );
  2728.   fprintf( ListFile, "\n" );
  2729.   ListWarnings();
  2730. }
  2731.  
  2732. #if ANSI
  2733.   static PROC void WriteCheckByte( long int *Check, unsigned char Value )
  2734. #else
  2735.   static PROC void WriteCheckByte( Check, Value )
  2736.   long int *Check;
  2737.   unsigned char Value;
  2738. #endif
  2739. {
  2740.   SymbolString MsbText;
  2741.   SymbolString LsbText;
  2742.  
  2743.   if( *HpHeadCond ) {
  2744.     if( fprintf( OutFile, "%s%s", NumberString( LsbText,
  2745.       ( long int )( Value & NibbleMask ), 16, 1 ), NumberString( MsbText,
  2746.       ( long int )(( Value >> 4 ) & NibbleMask ), 16, 1 )) <= 0 )
  2747.         RunError( True, FileWriteError );
  2748.   } else
  2749.     if( fprintf( OutFile, "%s", NumberString( MsbText, ( long int )Value,
  2750.       16, 2 )) <= 0 )
  2751.         RunError( True, FileWriteError );
  2752.   *Check = ((( *Check ) >> 4 ) ^ ((( Value ^ ( *Check )) & NibbleMask ) *
  2753.     CheckMagic ) & WordMask );
  2754.   *Check = ((( *Check ) >> 4 ) ^ (((( Value >> 4 ) ^ ( *Check )) &
  2755.     NibbleMask ) * CheckMagic ) & WordMask );
  2756. }
  2757.  
  2758. #if ANSI
  2759.   static PROC void WriteMemory( long int Start, long int Stop )
  2760. #else
  2761.   static PROC void WriteMemory( Start, Stop )
  2762.   long int Start;
  2763.   long int Stop;
  2764. #endif
  2765. {
  2766.   if( *HpAscCond ) {
  2767.     OutFile = freopen( OutFileName, "w+", OutFile );
  2768.     if( !OutFile )
  2769.       RunError( True, FileAccessError );
  2770.   }
  2771.   if( *HpHeadCond )
  2772.     if( *HpAscCond ) {
  2773.       if( fprintf( OutFile, "%s", AscHpHeadText ) <= 0 )
  2774.         RunError( True, FileWriteError );
  2775.     } else {
  2776.       unsigned char HpHeading[ BinHpHeadLength ];
  2777.       long int Size;
  2778.  
  2779.       Size = (( Stop - Start ) << 1 ) + 5;
  2780.       strcpy(( char * )HpHeading, BinHpHeadText );
  2781.       HpHeading[ BinHpHeadLength - 5 ] = 0x2c;
  2782.       HpHeading[ BinHpHeadLength - 4 ] = 0x2a;
  2783.       HpHeading[ BinHpHeadLength - 3 ] = ( unsigned char )( 0 | (( Size &
  2784.         0xfL ) << 4 ));
  2785.       HpHeading[ BinHpHeadLength - 2 ] = ( unsigned char )(( Size &
  2786.         0xff0L ) >> 4 );
  2787.       HpHeading[ BinHpHeadLength - 1 ] = ( unsigned char )(( Size &
  2788.         0xff000L ) >> 12 );
  2789.       if( fwrite(( char * )HpHeading, 1, BinHpHeadLength, OutFile ) !=
  2790.         BinHpHeadLength ) 
  2791.           RunError( True, FileWriteError );
  2792.     }
  2793.   if( *HpAscCond ) {
  2794.     SymbolString HexText;
  2795.     long int Count;
  2796.     long int Check;
  2797.  
  2798.     Check = 0L;
  2799.     if( *HpHeadCond ) {
  2800.       long int Size;
  2801.  
  2802.       Size = (( Stop - Start ) << 1 ) + 5;
  2803.       if( fprintf( OutFile, "\"" ) <= 0 )
  2804.         RunError( True, FileWriteError );
  2805.       WriteCheckByte( &Check, 0x2c );
  2806.       WriteCheckByte( &Check, 0x2a );
  2807.       WriteCheckByte( &Check, ( unsigned char )( 0 | (( Size & 0xfL ) << 4 )));
  2808.       WriteCheckByte( &Check, ( unsigned char )(( Size & 0xff0L ) >> 4 ));
  2809.       WriteCheckByte( &Check, ( unsigned char )(( Size & 0xff000L ) >> 12 ));
  2810.     }
  2811.     for( Count = Start; Count < Stop; Count++ ) {
  2812.       WriteCheckByte( &Check, Memory[ Count - StartAddress ]);
  2813.       if( !(( Count - Start + 6 ) % 32 ) && ( *HpHeadCond ))
  2814.         if( fprintf( OutFile, "\n" ) <= 0 )
  2815.           RunError( True, FileWriteError );
  2816.     }
  2817.     if( *HpHeadCond ) {
  2818.       for( Count = 0; Count < 4; Count++ ) 
  2819.         if( fprintf( OutFile, "%s", NumberString( HexText,
  2820.           ( Check >> ( 4 * Count )) & NibbleMask, 16, 1 )) <= 0 )
  2821.             RunError( True, FileWriteError );
  2822.       if( fprintf( OutFile, "\"" ) <= 0 )
  2823.         RunError( True, FileWriteError );
  2824.     }
  2825.   } else {
  2826.     unsigned int Size;
  2827.  
  2828.     if(( Stop - Start ) > 0L ) {
  2829.       Size = ( unsigned int )( Stop - Start );
  2830.       if( fwrite(( char * )&Memory[ Start - StartAddress ], 1, Size,
  2831.         OutFile ) != Size )
  2832.           RunError( True, FileWriteError );
  2833.     }
  2834.   }
  2835. }
  2836.  
  2837. #if ANSI
  2838.   PROC int main( int argc, char *argv[] )
  2839. #else
  2840.   PROC int main( argc, argv )
  2841.   int argc;
  2842.   char *argv[];
  2843. #endif
  2844. {
  2845.   InstPointer Inst; 
  2846.   unsigned int Count;
  2847.   
  2848.   if( fprintf( stderr, "%s\n\n", CopyRight ) <= 0 )
  2849.     RunError( True, FileWriteError );
  2850.   strcpy( Separator, "---------------------------------------" );
  2851.   strcat( Separator, "---------------------------------------" );
  2852.   for( Count = 0x0; Count < 0x100; Count++ )
  2853.     Operators[ Count ] = False;
  2854.   Operators[ StartChar ] = True;
  2855.   Operators[ StopChar ] = True;
  2856.   Operators[ PlusChar ] = True;
  2857.   Operators[ MinusChar ] = True;
  2858.   Operators[ NotChar ] = True;
  2859.   Operators[ PowerChar ] = True;
  2860.   Operators[ ShlChar ] = True;
  2861.   Operators[ ShrChar ] = True;
  2862.   Operators[ MulChar ] = True;
  2863.   Operators[ FracChar ] = True;
  2864.   Operators[ AndChar ] = True;
  2865.   Operators[ OrChar ] = True;
  2866.   Operators[ XorChar ] = True;
  2867.   Operators[ DivChar ] = True;
  2868.   Operators[ ModChar ] = True;
  2869.   if( OpenFiles( argc, argv )) {
  2870.     *StackPoint = True;
  2871.     StoreSymbolList( TokenText, 0, LastToken - 1, &Directives );
  2872.     StoreSymbolList( RegisterText, 0, LastReg - 1, &Registers );
  2873.     DefineSymbol( Super10Name, Super10Default, &Conditions, &NullLocation );
  2874.     Super10Cond = &( CurrentSymbol->Value );
  2875.     DefineSymbol( Chip48Name, Chip48Default, &Conditions, &NullLocation );
  2876.     Chip48Cond = &( CurrentSymbol->Value );
  2877.     DefineSymbol( UsedYesName, UsedYesDefault, &Conditions, &NullLocation );
  2878.     UsedYesCond = &( CurrentSymbol->Value );
  2879.     DefineSymbol( AlignOnName, AlignOnDefault, &Conditions, &NullLocation );
  2880.     AlignOnCond = &( CurrentSymbol->Value );
  2881.     DefineSymbol( HpAscName, HpAscDefault, &Conditions, &NullLocation );
  2882.     HpAscCond = &( CurrentSymbol->Value );
  2883.     DefineSymbol( Super11Name, Super11Default, &Conditions, &NullLocation );
  2884.     Super11Cond = &( CurrentSymbol->Value );
  2885.     DefineSymbol( XrefOnName, XrefOnDefault, &Conditions, &NullLocation );
  2886.     XrefOnCond = &( CurrentSymbol->Value );
  2887.     DefineSymbol( Chip8Name, Chip8Default, &Conditions, &NullLocation );
  2888.     Chip8Cond = &( CurrentSymbol->Value );
  2889.     DefineSymbol( HpHeadName, HpHeadDefault, &Conditions, &NullLocation );
  2890.     HpHeadCond = &( CurrentSymbol->Value );
  2891.     DefineSymbol( UsedOnName, UsedOnDefault, &Conditions, &NullLocation );
  2892.     UsedOnCond = &( CurrentSymbol->Value );
  2893.     DefineSymbol( XrefYesName, XrefYesDefault, &Conditions, &NullLocation );
  2894.     XrefYesCond = &( CurrentSymbol->Value );
  2895.     CurrentSymbol = NULL;
  2896.     Inst = NULL;
  2897.     DecodeFile( InFileName, &Inst, Directives, &Symbols, &Conditions );
  2898.     if( fprintf( stderr, "Done reading\n\n" ) <= 0 )
  2899.       RunError( True, FileWriteError );
  2900.     if( fprintf( ListFile, "Done reading\n\n" ) <= 0 )
  2901.       RunError( True, FileWriteError );
  2902.     ResolveEquations( Symbols );
  2903.     EncodeMemory( Instructions, Registers, Symbols, Conditions );
  2904.     WriteMemory( StartAddress, FinalAddress );
  2905.     if( OutFile )
  2906.       fclose( OutFile );
  2907.     OutFile = NULL;
  2908.     if( ListFile )
  2909.       if( ListFile != stdout )
  2910.         fclose( ListFile );
  2911.     ListFile = NULL;
  2912.     ReleaseSpace( &Space );
  2913.   }
  2914.   return( SuccessExitCode );
  2915. }
  2916.